Typesense Python Client

2.0.0 · active · verified Tue Mar 24

Official Python client for Typesense — open source typo-tolerant search engine, alternative to Algolia/Elasticsearch. Current version: 2.0.0 (Mar 2026). v2.0 added AsyncClient. Client takes a config dict with 'nodes' list — not a URL string. Typesense Cloud uses port 443 and HTTPS. Self-hosted uses port 8108 and HTTP by default.

Warnings

Install

Imports

Quickstart

Typesense Python client — collection creation, indexing, and search.

# pip install typesense
import typesense

# Self-hosted
client = typesense.Client({
    'nodes': [{'host': 'localhost', 'port': '8108', 'protocol': 'http'}],
    'api_key': 'your-api-key',
    'connection_timeout_seconds': 2
})

# Typesense Cloud
# client = typesense.Client({
#     'nodes': [{'host': 'xxx.a1.typesense.net', 'port': '443', 'protocol': 'https'}],
#     'api_key': 'your-cloud-api-key',
#     'connection_timeout_seconds': 2
# })

# Create collection with schema
client.collections.create({
    'name': 'books',
    'fields': [
        {'name': 'title', 'type': 'string'},
        {'name': 'author', 'type': 'string', 'facet': True},
        {'name': 'year', 'type': 'int32'}
    ]
})

# Index
client.collections['books'].documents.create({
    'id': '1', 'title': 'Dune', 'author': 'Herbert', 'year': 1965
})

# Search
result = client.collections['books'].documents.search({
    'q': 'dune',
    'query_by': 'title,author'
})
print(result['hits'])

view raw JSON →