Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor data stream uploading for client api #1172

Closed
asvetlov opened this issue Sep 14, 2016 · 7 comments
Closed

Refactor data stream uploading for client api #1172

asvetlov opened this issue Sep 14, 2016 · 7 comments
Labels
Milestone

Comments

@asvetlov
Copy link
Member

asvetlov commented Sep 14, 2016

Now aiohttp.ClientSession.request(..., data=data) supports too many available constructions:

  1. FormData
  2. asyncio.StreamReader
  3. aiohttp.StreamReader
  4. io.IOBase
  5. bytes
  6. bytearray
  7. streams.DataQueue
  8. coroutine with yields inside

I propose to drop (well, with deprecation period) two latest options but implement support for asynchronous iterators as data source.
Async generators is the most native way for upload BODY asynchronously IMHO.
Python 3.6 allows to write them with very elegant syntax (https://www.python.org/dev/peps/pep-0525/). As workaround for Python 3.5 user may use https://github.com/njsmith/async_generator

It should fix also long standing #183

@kxepal
Copy link
Member

kxepal commented Sep 14, 2016

Sounds good for me.
I wonder if it would be possible to implement some single interface that will cover all current cases and will let people pass various custom objects as data if they fulfil it?

@asvetlov
Copy link
Member Author

asvetlov commented Sep 14, 2016

I have no idea how this single interface should look like.
For me byte and file API is good for simple cases and async generator covers all complex needs.
Hmm, we could drop bullets 2 and 3 as well: asyncio.StreamReader and aiohttp.StreamReader both support async iteration protocol :)

@dhrp
Copy link

dhrp commented Oct 28, 2016

I ran into something I don't understand on this topic, and posted on Stackoverflow. Is this related?

http://stackoverflow.com/questions/40299114/with-aiohttp-post-how-do-i-pass-it-some-data-to-iterate

@asvetlov
Copy link
Member Author

I don't understand do you have problems with your example or not?

Yes, coroutine support should be deprecated but it still exists and working.
See https://github.com/KeepSafe/aiohttp/blob/master/tests/test_client_functional_oldstyle.py#L427-L457 for unit test.

@fafhrd91
Copy link
Member

I am working on refactoring in payload-refactoring branch #1664

@fafhrd91 fafhrd91 modified the milestones: 2.0, 2.1 Feb 22, 2017
@fafhrd91
Copy link
Member

merged

@lock
Copy link

lock bot commented Oct 29, 2019

This thread has been automatically locked since there has not been
any recent activity after it was closed. Please open a new issue for
related bugs.

If you feel like there's important points made in this discussion,
please include those exceprts into that new issue.

@lock lock bot added the outdated label Oct 29, 2019
@lock lock bot locked as resolved and limited conversation to collaborators Oct 29, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

4 participants