An efficient connection pool for Weaviate clients.
Project description
Here's the corrected README file for the Weaviate Connection Pool module:
Weaviate Connection Pool
This Python module provides a thread-safe singleton connection pool for Weaviate clients. It ensures efficient management of Weaviate client instances for applications requiring multiple, concurrent connections to a Weaviate database. The connection pool dynamically creates new client instances on demand and reuses them to handle multiple requests, improving performance and resource utilization.
Features
- Singleton Connection Pool: Ensures a single instance of the connection pool throughout the application.
- Thread-Safe: Safely handles concurrent access from multiple threads.
- Dynamic Client Management: Dynamically creates and reuses Weaviate client instances as needed.
- Timeout for Client Acquisition: Supports timeouts when waiting for an available client, preventing indefinite blocking.
- Automatic Client Release: Automatically returns clients to the pool for reuse after their task is completed.
How to Use
Initialization
To use the connection pool, first initialize it with the Weaviate database URL, authentication credentials (if required), the desired pool size, and an optional timeout for waiting for a client.
from pool import WeaviateConnectionPool
# Initialize the connection pool
pool = WeaviateConnectionPool(url="http://localhost:8080", auth_client_secret="your_secret", pool_size=10, waiting_time_out=300)
Getting a Client
When you need to interact with the Weaviate database, get a client from the pool:
try:
client = pool.get_client()
# Use the client for database operations
finally:
pool.release_client(client)
Releasing a Client
After finishing the database operations, release the client back to the pool for reuse:
pool.release_client(client)
Error Handling
- TimeoutError: If a client is not available within the specified timeout period, a
TimeoutError
is raised. - General Exceptions: For any other issues while acquiring or releasing clients, a general exception is raised with an appropriate error message.
Best Practices
- Always release clients back to the pool to ensure they are available for reuse.
- Handle exceptions gracefully, especially
TimeoutError
, to avoid application crashes due to unavailable clients. - Adjust the pool size based on your application's concurrency requirements and resource availability.
This connection pool implementation simplifies managing Weaviate connections in multi-threaded applications, ensuring efficient and scalable database access.
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
Built Distribution
File details
Details for the file weaviate-connection-pool-0.1.0.tar.gz
.
File metadata
- Download URL: weaviate-connection-pool-0.1.0.tar.gz
- Upload date:
- Size: 4.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.0 CPython/3.8.19
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | eb4212f5e30b19e317be472c1accd4c5000091e729b78ae914240e2099a2efa8 |
|
MD5 | 2045c29350fce55435c1a6f09ae67129 |
|
BLAKE2b-256 | f7709066ca936100de7df8b69fb086e2cdeab1c27147e40bdd1576f9fbeb92a6 |
File details
Details for the file weaviate_connection_pool-0.1.0-py3-none-any.whl
.
File metadata
- Download URL: weaviate_connection_pool-0.1.0-py3-none-any.whl
- Upload date:
- Size: 4.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.0 CPython/3.8.19
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4d166f178e084249c8841a2e52bed4f58008879f1f7a1ffbec663c5e6cd065a3 |
|
MD5 | d103734d457e5b768e0d1583a31e332a |
|
BLAKE2b-256 | 5ad33bfe0b4672c6aa7cc0591dc0d5a72bbcc242e85c2206ae333f2db3e270cc |