Python connector for AsterixDB
Project description
PyAsterix: Python Connector for AsterixDB
PyAsterix is a feature-rich Python library designed for seamless interaction with AsterixDB, a scalable NoSQL database management system. It offers two powerful interfaces: a low-level DB-API compliant interface and a high-level DataFrame API.
Table of Contents
Installation
Install from PyPI:
pip install pyasterix
With observability extras (Prometheus + OpenTelemetry):
pip install "pyasterix[observability]"
Install from source (editable for development):
git clone https://github.com/your-org/pyasterix.git
cd pyasterix
python -m venv .venv
".venv"/Scripts/activate
pip install -U pip build twine
pip install -e .
Features
Core Features
- PEP 249 compliant database interface
- Pandas-like DataFrame API
- Support for both synchronous and asynchronous queries
- Comprehensive error handling with custom, context-rich exceptions
- Connection pooling and intelligent connection management
- Native support for AsterixDB data types
- Easy integration with pandas ecosystem
- Built-in observability: metrics (Prometheus), tracing (OpenTelemetry), structured logging
DB-API Features
- Standard cursor interface
- Transaction support (where applicable)
- Parameterized queries
- Multiple result fetch methods
Advanced Features
- Observability (metrics, tracing, logging) with production-ready configuration
- Async query support (status/result handles, pooled polling)
- Connection pool lifecycle management (validation, idle expiry, cleanup thread)
- Error mapping from HTTP/AsterixDB payloads to precise exceptions
- DataFrame API Features
- Intuitive query building
- Method chaining
- Complex aggregations
- Join operations
- Filtering and sorting
- Group by operations
- Direct pandas DataFrame conversion
Architecture
Components
Connection Management
- Connection pooling and lifecycle (validation, idle/lifetime expiry, background cleanup)
- Session handling via HTTP sessions
- Query execution including async/deferred modes
Query Building
- SQL++ query generation
- Parameter binding
- Query validation
Result Processing
- Type conversion
- Result caching
- Data streaming
Observability
- Metrics: query durations, counts, rows fetched, pool gauges, error counters
- Tracing: spans for execute/fetch/async/pool and DataFrame operations (OTel compatible)
- Logging: structured JSON with trace correlation and performance-aware filtering
Exception Handling
- PEP 249 standard hierarchy + AsterixDB-specific exceptions (HTTPError, NetworkError, TimeoutError, SyntaxError, IdentifierError, AsyncQueryError, PoolExhaustedError, etc.)
- Rich error context attached to each exception and
.to_dict()serialization
Best Practices
Connection Management
- Use context managers (with statements)
- Close connections explicitly
- Implement connection pooling for web applications and batch services
Query Optimization
- Use appropriate indexes
- Leverage query hints when necessary
- Monitor query performance
Error Handling
- Implement proper exception handling
- Use retry mechanisms for transient failures
- Log errors appropriately
- Prefer catching specific driver exceptions (e.g., SyntaxError, NetworkError, TimeoutError)
- Inspect
.contexton exceptions and leverage.to_dict()for structured logging
Observability
- Enable metrics and tracing in non-prod first; tune sampling in prod
- Export Prometheus metrics and view traces via OTLP/Jaeger
- Use structured logs with correlation IDs for cross-service debugging
Documentation
- Driver Overview:
docs/DRIVER_OVERVIEW.md - DB-API Guide:
docs/DBAPI_GUIDE.md - DataFrame Guide:
docs/DATAFRAME_GUIDE.md - Observability for Developers:
docs/OBSERVABILITY_FOR_DEVELOPERS.md - Exception Handling:
docs/EXCEPTION_HANDLING.md
Contributing
- We welcome contributions! Please follow these steps:
- Fork the repository
- Create a feature branch
- Commit your changes
- Create a pull request
License
- This project is licensed under the MIT License - see the LICENSE file for details.
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
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file pyasterix-0.1.2.tar.gz.
File metadata
- Download URL: pyasterix-0.1.2.tar.gz
- Upload date:
- Size: 62.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
682887cbf80301d576b608311fc3943ce3b5ad6611111c546cb5579cbce6d14b
|
|
| MD5 |
f312ac9df98e384416704dd52d630771
|
|
| BLAKE2b-256 |
8ae93cd5d5233e1eaeafeb65bf59f65a901dc89756f0e6d2b69109278c360c26
|
File details
Details for the file pyasterix-0.1.2-py3-none-any.whl.
File metadata
- Download URL: pyasterix-0.1.2-py3-none-any.whl
- Upload date:
- Size: 49.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a852592e53e28f4662a05d17ff63225083cca821e78397e9cc76080797db0f8e
|
|
| MD5 |
11a1a460be7fd1f63ce3b1097a116217
|
|
| BLAKE2b-256 |
b54e9b0cd3802869198db5cf6bca2184660767469039526d96cf830d3622efd1
|