Client library for the Qdrant vector search engine
—
Client initialization, connection management, and configuration options for both synchronous and asynchronous operations.
Initialize client for local development without running a separate Qdrant server.
class QdrantClient:
def __init__(
self,
location: Optional[str] = None,
url: Optional[str] = None,
port: Optional[int] = 6333,
grpc_port: Optional[int] = 6334,
prefer_grpc: bool = False,
https: Optional[bool] = None,
api_key: Optional[str] = None,
prefix: Optional[str] = None,
timeout: Optional[float] = None,
host: Optional[str] = None,
path: Optional[str] = None,
force_disable_check_same_thread: bool = False,
**kwargs
):
"""
Initialize Qdrant client.
Parameters:
- location: Connection string (":memory:", path, or None for remote)
- url: Full URL to Qdrant server
- host: Hostname for Qdrant server
- port: HTTP port (default: 6333)
- grpc_port: gRPC port (default: 6334)
- prefer_grpc: Use gRPC when available
- https: Use HTTPS connection
- api_key: Bearer token for authentication
- prefix: URL prefix for API endpoints
- timeout: Request timeout in seconds
- path: Local storage path for file-based mode
- force_disable_check_same_thread: Disable SQLite same-thread check
"""Usage examples:
# In-memory mode (data lost on exit)
client = QdrantClient(":memory:")
# Persistent local storage
client = QdrantClient(path="./qdrant_storage")
# Remote server
client = QdrantClient(host="localhost", port=6333)
client = QdrantClient(url="http://localhost:6333")
# Remote server with gRPC
client = QdrantClient(host="localhost", grpc_port=6334, prefer_grpc=True)
# Qdrant Cloud with authentication
client = QdrantClient(
url="https://xyz.aws.cloud.qdrant.io:6333",
api_key="your-api-key"
)Asynchronous client providing the same API with async/await support.
class AsyncQdrantClient:
def __init__(
self,
location: Optional[str] = None,
url: Optional[str] = None,
port: Optional[int] = 6333,
grpc_port: Optional[int] = 6334,
prefer_grpc: bool = False,
https: Optional[bool] = None,
api_key: Optional[str] = None,
prefix: Optional[str] = None,
timeout: Optional[float] = None,
host: Optional[str] = None,
path: Optional[str] = None,
**kwargs
):
"""Async version of QdrantClient with identical parameters."""Usage example:
import asyncio
from qdrant_client import AsyncQdrantClient
async def main():
client = AsyncQdrantClient(url="http://localhost:6333")
collections = await client.get_collections()
await client.close()
asyncio.run(main())Methods for managing client connections and resources.
def close(self) -> None:
"""Close client connections and cleanup resources."""
async def aclose(self) -> None:
"""Async version: Close client connections and cleanup resources."""Verify client connectivity and server health.
def get_collections(self) -> CollectionsResponse:
"""
Get list of collections.
Returns:
CollectionsResponse: List of collection descriptions
"""
def collection_exists(self, collection_name: str) -> bool:
"""
Check if collection exists.
Parameters:
- collection_name: Name of collection to check
Returns:
bool: True if collection exists
"""class BearerAuth:
def __init__(self, token: str):
"""
Bearer token authentication.
Parameters:
- token: Bearer authentication token
"""The client automatically handles REST and gRPC protocol selection and conversion:
prefer_grpc=True to use gRPC when availableCommon exceptions thrown by client operations:
class UnexpectedResponse(Exception):
"""Raised when server returns unexpected response."""
class ResponseHandlingError(Exception):
"""Raised when response cannot be processed."""
class QdrantConnectionError(Exception):
"""Raised when connection to Qdrant server fails."""Install with Tessl CLI
npx tessl i tessl/pypi-qdrant-client