https://github.com/moshe/asonic
async python client for the sonic search backend
https://github.com/moshe/asonic
Last synced: 21 days ago
JSON representation
async python client for the sonic search backend
- Host: GitHub
- URL: https://github.com/moshe/asonic
- Owner: moshe
- License: mpl-2.0
- Created: 2019-03-25T10:54:03.000Z (about 6 years ago)
- Default Branch: master
- Last Pushed: 2025-03-07T18:17:40.000Z (about 2 months ago)
- Last Synced: 2025-04-04T01:28:45.944Z (30 days ago)
- Language: Python
- Homepage:
- Size: 49.8 KB
- Stars: 134
- Watchers: 3
- Forks: 11
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
- License: LICENSE.md
Awesome Lists containing this project
README
# asonic - async python client for the sonic search backend
Asonic implements all [Sonic](https://github.com/valeriansaliou/sonic) APIs
Bugfixes and api changes are welcome## Install
`pip install asonic`## API Docs
[here](https://asonic.readthedocs.io/en/latest/asonic.html#module-asonic.client)## Usage
### Search channel
```python
import asynciofrom asonic import Client
from asonic.enums import Channelasync def main():
c = await Client.create(
host="127.0.0.1",
port=1491,
password="SecretPassword",
channel=Channel.SEARCH,
max_connections=100
)
assert (await c.query('collection', 'bucket', 'quick')) == [b'user_id']
assert (await c.suggest('collection', 'bucket', 'br', 1)) == [b'brown']if __name__ == '__main__':
loop = asyncio.get_event_loop()
loop.run_until_complete(main())
```### Ingest channel
```python
import asynciofrom asonic import Client
from asonic.enums import Channelasync def main():
c = await Client.create(
host="127.0.0.1",
port=1491,
password="SecretPassword",
channel=Channel.INGEST,
max_connections=100
)
await c.push('collection', 'bucket', 'user_id', 'The quick brown fox jumps over the lazy dog')
# Return b'OK'
await c.pop('collection', 'bucket', 'user_id', 'The')
# Return 1if __name__ == '__main__':
loop = asyncio.get_event_loop()
loop.run_until_complete(main())
```### Control channel
```python
import asynciofrom asonic import Client
from asonic.enums import Channel, Actionasync def main():
c = await Client.create(
host="127.0.0.1",
port=1491,
password="SecretPassword",
channel=Channel.CONTROL,
)
await c.trigger(Action.CONSOLIDATE)
# Return b'OK'if __name__ == '__main__':
loop = asyncio.get_event_loop()
loop.run_until_complete(main())
```