PyAsyncSQL
PyAsyncSQL is an ultra-fast, asynchronous SQL layer that mimics MongoDB-style operations with full Redis caching and background write queue support.
It’s designed for high-performance systems that need MongoDB-like flexibility over PostgreSQL.
🚀 Features
- ⚡ Async I/O – Fully asynchronous using
aiopgandaioredis - 🧠 MongoDB-like syntax – Use familiar methods like
find_one,insert_one,update_many, etc. - 🔁 Redis caching – Automatic query caching with TTL
- 🧩 Background SQL Worker Queue – Batched inserts/updates/deletes to reduce I/O overhead
- 🔎 Pub/Sub Watcher – Real-time change streaming via Redis channels
- 💥 Automatic Retry + Reconnect – Fault-tolerant retry for transient SQL/Redis errors
- 🧰 Dynamic Collections – Access collections as attributes or subscripts (e.g.
db.usersordb["users"]) - 🧹 Safe Shutdown – Waits for all pending operations before closing
🧑💻 Installation
pip install pyasyncsql
⚙️ Quick Start
import asyncio
from pyasyncsql import AsyncSqlDB
DSN = "postgres://user:password@hostname:port/dbname?sslmode=require"
REDIS_URL = "redis://localhost:6379"
async def main():
db = AsyncSqlDB(DSN, REDIS_URL)
await db.connect()
users = db["users"]
# Insert
await users.insert_one({"name": "Alice", "age": 25})
# Find
user = await users.find_one({"name": "Alice"})
print(user)
# Update
await users.update_many({"name": "Alice"}, {"$set": {"age": 26}})
# Delete
await users.delete_one({"name": "Alice"})
# Close safely (waits for background queue to finish)
await db.close()
asyncio.run(main())
🔄 Watcher (Real-Time Stream)
import asyncio
async def listener(data):
print("Database change detected:", data)
async def watch_changes():
db = AsyncSqlDB(DSN, REDIS_URL)
await db.connect()
users = db["users"]
await users.watch(listener)
asyncio.run(watch_changes())
🧮 API Reference
AsyncSqlDB
| Method | Description |
|---|---|
connect() |
Initialize PostgreSQL + Redis connection |
close() |
Gracefully close and flush all background tasks |
__getitem__ / __getattr__ |
Access collection dynamically |
AsyncMongoLikeCollection
| Method | Description |
|---|---|
find_one(filter) |
Fetch one document |
find(filter) |
Return list of matching documents |
insert_one(doc) |
Insert a new document |
insert_many(docs) |
Insert multiple documents |
update_one(filter, update) |
Update a single document |
update_many(filter, update) |
Update multiple documents |
delete_one(filter) |
Delete a single document |
delete_many(filter) |
Delete multiple documents |
count_documents(filter) |
Count matching documents |
watch(callback) |
Listen for real-time change events via Redis |
🧱 Background Worker Queue
All write operations (insert/update/delete) are queued and flushed in batches to PostgreSQL, improving throughput dramatically under high load.
await db.close() # ensures all batched operations are written before shutdown
⚠️ Error Handling
- Automatic retries with exponential backoff for SQL and Redis operations
- Transparent reconnects for transient connection failures
- Warnings are logged via Python’s
loggingmodule
🧰 Example Architecture
┌────────────────┐
│ Your App │
└──────┬─────────┘
│
Async API Calls
│
┌──────▼─────────┐
│ PyAsyncSQL │
│ (Mongo-like) │
└──────┬─────────┘
│
┌──────────┴───────────┐
│ │
┌────▼─────┐ ┌────▼────┐
│PostgreSQL│ │ Redis │
│(storage) │ │(cache + │
│ │ │ pub/sub)│
└──────────┘ └─────────┘
🧾 License
MIT License © 2025 Sathishzus
💬 Author
Sathishzus – Open Source Systems & Cloud Performance Tools
🔗 GitHub | 🌐 Website
Metadata
Release files for asyncsqlpy 0.1.8
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| asyncsqlpy-0.1.8.tar.gz | 8.4 kB | Without provenance | Details for asyncsqlpy-0.1.8.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| asyncsqlpy-0.1.8-py3-none-any.whl | Python 3 | none | any | Details for asyncsqlpy-0.1.8-py3-none-any.whl |
Total release size: 16.9 kB
Release files / asyncsqlpy-0.1.8.tar.gz
| Download URL | asyncsqlpy-0.1.8.tar.gz |
|---|---|
| Size | 8.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
381791c872d0e31e42476e50c50f223eb0b5fd64cf723731ef311ac17e49e228
|
|
BLAKE2b-256 checksum How to use checksums |
6a9b22c67cdaa84450012d6e71d212399677280bccbd9a5c74abed05fca43303
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.12.1
|
Release files / asyncsqlpy-0.1.8-py3-none-any.whl
| Download URL | asyncsqlpy-0.1.8-py3-none-any.whl |
|---|---|
| Size | 8.4 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
727a45f98dffcc5fe1f4b0bd91bb6e4b0ee4562cc96c38a5b35094752996df79
|
|
BLAKE2b-256 checksum How to use checksums |
67ac2bb4fda0771d2e538c8442237eef62d83fd92214eb37ca6f6b414b876226
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.12.1
|
Security for asyncsqlpy 0.1.8
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.