Skip to content

Commit

Permalink
Experimental support for asyncio (#49)
Browse files Browse the repository at this point in the history
  • Loading branch information
pavius authored Sep 14, 2020
1 parent 0edd8da commit 87c7a42
Show file tree
Hide file tree
Showing 15 changed files with 1,745 additions and 4 deletions.
1 change: 1 addition & 0 deletions Pipfile
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,4 @@ twine = "*"
requests = ">=2.19.1"
future = ">=0.18.2"
ujson = "~=2.0"

33 changes: 33 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -208,5 +208,38 @@ for record in response.output.records:
v3io_client.stream.delete(container='users', stream_path='/my-test-stream')
```

## Support for asyncio (experimental)

All synchronous APIs are available as `async` interfaces through the `aio` module. The differences between the sync and async API is as follows:
1. You must initialize a different client (`v3io.aio.dataplane.Client`) from `v3io.aio.dataplane`
2. All interfaces should be called with `await`
3. `v3io.aio.dataplane.RaiseForStatus.never` should be used over `v3io.dataplane.RaiseForStatus.never` (although they are the same)
4. The batching functionality doesn't exist, as you can achieve the same through standard asyncio practices

Note: For the time being, `aiohttp` must be provided externally - it is not a v3io-py dependency. This will be fixed in future versions.

```python
import v3io.aio.dataplane

v3io_client = v3io.aio.dataplane.Client(endpoint='https://v3io-webapi:8081', access_key='some_access_key')

# put contents to some object
await v3io_client.object.put(container='users',
path='/my-object',
body='hello, there')

# get the object
response = await v3io_client.object.get(container='users', path='/my-object')

# print the contents. outputs:
#
# hello, there
#
print(response.body.decode('utf-8'))

# delete the object
await v3io_client.object.delete(container='users', path='/my-object')
```

# Controlplane client
Coming soon.
3 changes: 3 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ def load_deps(section):
'v3io.common',
'v3io.dataplane',
'v3io.dataplane.transport',
'v3io.aio.dataplane',
'v3io.aio.dataplane.transport',
'v3io.logger'
],
install_requires=install_requires,
Expand All @@ -80,6 +82,7 @@ def load_deps(section):
'Programming Language :: Python :: 3',
'Programming Language :: Python :: 3.6',
'Programming Language :: Python :: 3.7',
'Programming Language :: Python :: 3.8',
'Programming Language :: Python',
'Topic :: Software Development :: Libraries :: Python Modules',
'Topic :: Software Development :: Libraries',
Expand Down
Loading

0 comments on commit 87c7a42

Please sign in to comment.