Async library for Typesense
Project description
aio_typesense
Async Library for Typesense with type hints
pip install aio_typesense
Usage
# examples/example.py
import asyncio
from typing import TypedDict, List
from aio_typesense import Client, Collection
class Movie(TypedDict):
id: str
name: str
year: int
MOVIES: List[Movie] = [
{"id": "id1", "name": "Wonder Woman", "year": 2017, "year_facet": "2017"},
{"id": "id2", "name": "Justice League", "year": 2017, "year_facet": "2017"},
{"id": "id3", "name": "Wonder Woman 1984", "year": 2020, "year_facet": "2020"},
{"id": "id4", "name": "Death on the Nile", "year": 2021, "year_facet": "2021"},
]
async def main():
client = Client(
node_urls=["http://localhost:8108"],
api_key="Rhsdhas2asasdasj2",
)
r = await client.collections.create(
{
"name": "movies",
"num_documents": 0,
"fields": [
{
"name": "name",
"type": "string",
},
{
"name": "year",
"type": "int32",
},
{
"name": "year_facet",
"type": "string",
"facet": True,
},
],
"default_sorting_field": "year",
}
)
collection: Collection[Movie] = client.collections["movies"]
r = await collection.documents.create_many(documents=MOVIES)
print(r)
search_r = await collection.documents.search(
{
"q": "wonder woman 2021",
"query_by": "year_facet,name",
"query_by_weights": "1,1",
}
)
print(search_r["hits"])
# [
# {
# "document": {
# "id": "id3",
# "name": "Wonder Woman 1984",
# "year": 2020,
# "year_facet": "2020",
# },
# "highlights": [
# {
# "field": "year_facet",
# "matched_tokens": ["2020"],
# "snippet": "<mark>2020</mark>",
# }
# ],
# "text_match": 1125899907169635,
# },
# {
# "document": {
# "id": "id1",
# "name": "Wonder Woman",
# "year": 2017,
# "year_facet": "2017",
# },
# "highlights": [
# {
# "field": "year_facet",
# "matched_tokens": ["2017"],
# "snippet": "<mark>2017</mark>",
# }
# ],
# "text_match": 1125899907169379,
# },
# {
# "document": {
# "id": "id4",
# "name": "Death on the Nile",
# "year": 2021,
# "year_facet": "2021",
# },
# "highlights": [
# {
# "field": "year_facet",
# "matched_tokens": ["2021"],
# "snippet": "<mark>2021</mark>",
# }
# ],
# "text_match": 562949953552128,
# },
# {
# "document": {
# "id": "id2",
# "name": "Justice League",
# "year": 2017,
# "year_facet": "2017",
# },
# "highlights": [
# {
# "field": "year_facet",
# "matched_tokens": ["2017"],
# "snippet": "<mark>2017</mark>",
# }
# ],
# "text_match": 562949953551616,
# },
# ]
if __name__ == "__main__":
asyncio.run(main())
Contributing
Prerequisites:
- poetry
- nox
- nox-poetry
Install them on your system:
pip install poetry nox nox-poetry
Run tests:
nox
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
aio_typesense-0.1.0.tar.gz
(6.4 kB
view details)
Built Distribution
File details
Details for the file aio_typesense-0.1.0.tar.gz
.
File metadata
- Download URL: aio_typesense-0.1.0.tar.gz
- Upload date:
- Size: 6.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.1.4 CPython/3.9.1 Linux/5.4.87-1-lts
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | dbe0e45e44cc82b70b820cb5d8bc5b169350694a63934ef3f5064b72cd0690f9 |
|
MD5 | fc1f6d793ff59693229d0a7f46ccbf1a |
|
BLAKE2b-256 | 3371ee40f5aee2dcbff3f4e9d31c1abc73406610b80af382718a280e8f7135e4 |
File details
Details for the file aio_typesense-0.1.0-py3-none-any.whl
.
File metadata
- Download URL: aio_typesense-0.1.0-py3-none-any.whl
- Upload date:
- Size: 7.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.1.4 CPython/3.9.1 Linux/5.4.87-1-lts
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | ea5c676fe641040a19dd2c4f616183bb2712cd3e1e6ba664436707c17c8021f9 |
|
MD5 | 8870db43ff708ac7eb50a67d3c3cde97 |
|
BLAKE2b-256 | bc9e52c9eca34e6fd51966aba1eb139f7a0017c0ca936d54b566614a948628fe |