allensdk.brain_observatory.ecephys.ecephys_project_api.http_engine module¶
-
class
allensdk.brain_observatory.ecephys.ecephys_project_api.http_engine.
AsyncHttpEngine
(scheme: str, host: str, session: Optional[aiohttp.client.ClientSession] = None, **kwargs)[source]¶ Bases:
allensdk.brain_observatory.ecephys.ecephys_project_api.http_engine.HttpEngine
-
stream
(self, route: str) → Callable[[Callable[[AsyncIterator[bytes]], Awaitable[NoneType]]], Awaitable[NoneType]][source]¶ - Returns a coroutine which
- makes an http request
- exposes internally an asynchronous iterator over the response
- takes a callback parameter, which should consume the iterator.
Parameters: - route :
the http route (under this object’s host) to request against.
Notes
To use this method, you will need an appropriate consumer. For instance, If you want to write the streamed data to a local file, you can use write_bytes_from_coroutine.
Examples
>>> engine = AsyncHttpEngine("http", "examplehost") >>> stream_coro = engine.stream("example/route") >>> write_bytes_from_coroutine("example/file/path.txt", stream_coro)
-
-
class
allensdk.brain_observatory.ecephys.ecephys_project_api.http_engine.
HttpEngine
(scheme: str, host: str, timeout: float = 600, chunksize: int = 10240, **kwargs)[source]¶ Bases:
object
-
allensdk.brain_observatory.ecephys.ecephys_project_api.http_engine.
write_bytes_from_coroutine
(path: str, coroutine: Callable[[Callable[[AsyncIterator[bytes]], Awaitable[NoneType]]], Awaitable[NoneType]])[source]¶ Utility for streaming http from an asynchronous requester to a file.
Parameters: - path :
Write to this file
- coroutine :
- The source of the data. Needs to have a specific structure, namely:
- the first-position parameter of the coroutine ought to accept a
callback. This callback ought to itself be awaitable. - within the coroutine, this callback ought to be called with a single argument. That single argument should be an asynchronous iterator.
Please see AsyncHttpEngine.stream (and AsyncHttpEngine._stream_coroutine) for an example.