0
# Client Setup
1
2
Client initialization, connection management, and configuration options for both synchronous and asynchronous operations.
3
4
## Capabilities
5
6
### Local Mode Initialization
7
8
Initialize client for local development without running a separate Qdrant server.
9
10
```python { .api }
11
class QdrantClient:
12
def __init__(
13
self,
14
location: Optional[str] = None,
15
url: Optional[str] = None,
16
port: Optional[int] = 6333,
17
grpc_port: Optional[int] = 6334,
18
prefer_grpc: bool = False,
19
https: Optional[bool] = None,
20
api_key: Optional[str] = None,
21
prefix: Optional[str] = None,
22
timeout: Optional[float] = None,
23
host: Optional[str] = None,
24
path: Optional[str] = None,
25
force_disable_check_same_thread: bool = False,
26
**kwargs
27
):
28
"""
29
Initialize Qdrant client.
30
31
Parameters:
32
- location: Connection string (":memory:", path, or None for remote)
33
- url: Full URL to Qdrant server
34
- host: Hostname for Qdrant server
35
- port: HTTP port (default: 6333)
36
- grpc_port: gRPC port (default: 6334)
37
- prefer_grpc: Use gRPC when available
38
- https: Use HTTPS connection
39
- api_key: Bearer token for authentication
40
- prefix: URL prefix for API endpoints
41
- timeout: Request timeout in seconds
42
- path: Local storage path for file-based mode
43
- force_disable_check_same_thread: Disable SQLite same-thread check
44
"""
45
```
46
47
Usage examples:
48
49
```python
50
# In-memory mode (data lost on exit)
51
client = QdrantClient(":memory:")
52
53
# Persistent local storage
54
client = QdrantClient(path="./qdrant_storage")
55
56
# Remote server
57
client = QdrantClient(host="localhost", port=6333)
58
client = QdrantClient(url="http://localhost:6333")
59
60
# Remote server with gRPC
61
client = QdrantClient(host="localhost", grpc_port=6334, prefer_grpc=True)
62
63
# Qdrant Cloud with authentication
64
client = QdrantClient(
65
url="https://xyz.aws.cloud.qdrant.io:6333",
66
api_key="your-api-key"
67
)
68
```
69
70
### Async Client Initialization
71
72
Asynchronous client providing the same API with async/await support.
73
74
```python { .api }
75
class AsyncQdrantClient:
76
def __init__(
77
self,
78
location: Optional[str] = None,
79
url: Optional[str] = None,
80
port: Optional[int] = 6333,
81
grpc_port: Optional[int] = 6334,
82
prefer_grpc: bool = False,
83
https: Optional[bool] = None,
84
api_key: Optional[str] = None,
85
prefix: Optional[str] = None,
86
timeout: Optional[float] = None,
87
host: Optional[str] = None,
88
path: Optional[str] = None,
89
**kwargs
90
):
91
"""Async version of QdrantClient with identical parameters."""
92
```
93
94
Usage example:
95
96
```python
97
import asyncio
98
from qdrant_client import AsyncQdrantClient
99
100
async def main():
101
client = AsyncQdrantClient(url="http://localhost:6333")
102
collections = await client.get_collections()
103
await client.close()
104
105
asyncio.run(main())
106
```
107
108
### Connection Management
109
110
Methods for managing client connections and resources.
111
112
```python { .api }
113
def close(self) -> None:
114
"""Close client connections and cleanup resources."""
115
116
async def aclose(self) -> None:
117
"""Async version: Close client connections and cleanup resources."""
118
```
119
120
### Connection Testing
121
122
Verify client connectivity and server health.
123
124
```python { .api }
125
def get_collections(self) -> CollectionsResponse:
126
"""
127
Get list of collections.
128
129
Returns:
130
CollectionsResponse: List of collection descriptions
131
"""
132
133
def collection_exists(self, collection_name: str) -> bool:
134
"""
135
Check if collection exists.
136
137
Parameters:
138
- collection_name: Name of collection to check
139
140
Returns:
141
bool: True if collection exists
142
"""
143
```
144
145
## Authentication
146
147
```python { .api }
148
class BearerAuth:
149
def __init__(self, token: str):
150
"""
151
Bearer token authentication.
152
153
Parameters:
154
- token: Bearer authentication token
155
"""
156
```
157
158
## Protocol Configuration
159
160
The client automatically handles REST and gRPC protocol selection and conversion:
161
162
- **REST API**: Default HTTP protocol using JSON
163
- **gRPC API**: High-performance binary protocol
164
- **Automatic Conversion**: Seamless conversion between REST and gRPC data structures
165
- **Protocol Selection**: Specify `prefer_grpc=True` to use gRPC when available
166
167
## Error Handling
168
169
Common exceptions thrown by client operations:
170
171
```python { .api }
172
class UnexpectedResponse(Exception):
173
"""Raised when server returns unexpected response."""
174
175
class ResponseHandlingError(Exception):
176
"""Raised when response cannot be processed."""
177
178
class QdrantConnectionError(Exception):
179
"""Raised when connection to Qdrant server fails."""
180
```