Raccoon Tools DB
A managed PostgreSQL connection pool (via psycopg 3) with opt-in FastAPI and OpenTelemetry integrations.
Installation
Base install:
uv add raccoontools-db
With OpenTelemetry instrumentation:
uv add raccoontools-db[otel]
With FastAPI OTEL instrumentation:
uv add raccoontools-db[fastapi]
All extras:
uv add raccoontools-db[all]
Functionalities
Connection Pool (raccoontools_db.pool)
Provides a module-level singleton connection pool with a simple create/get/close lifecycle.
PoolConfig
Configuration dataclass for the connection pool.
Fields:
conn_info(str): PostgreSQL connection string.min_size(int): Minimum connections in pool (default: 2).max_size(int): Maximum connections in pool (default: 10).use_otel(bool): Enable OpenTelemetry tracing (default: False).otel_service_name(str): Service name for OTEL (required whenuse_otel=True).otel_exporter_endpoint(str): OTLP exporter endpoint (required whenuse_otel=True).otel_use_http(bool): Use HTTP protocol for OTLP (default: True).
create_pool(config: PoolConfig) -> None
Creates and opens the global connection pool. Raises RuntimeError if a pool already exists.
get_pool() -> ConnectionPool
Returns the active pool. Raises RuntimeError if the pool has not been created.
close_pool() -> None
Closes the pool and resets state. Safe to call if already closed or never created.
Example: Plain usage (no FastAPI, no OTEL)
from raccoontools_db.pool import PoolConfig, create_pool, get_pool, close_pool
config = PoolConfig(conn_info="postgresql://user:pass@localhost:5432/mydb")
create_pool(config)
pool = get_pool()
with pool.connection() as conn:
with conn.cursor() as cur:
cur.execute("SELECT 1")
print(cur.fetchone())
close_pool()
Example: With OpenTelemetry
from raccoontools_db.pool import PoolConfig, create_pool, get_pool, close_pool
config = PoolConfig(
conn_info="postgresql://user:pass@localhost:5432/mydb",
use_otel=True,
otel_service_name="my-service",
otel_exporter_endpoint="http://localhost:4318",
)
create_pool(config)
pool = get_pool()
# Use pool as normal — logging is handled via OTEL tracing
FastAPI Integration (raccoontools_db.fastapi)
create_lifespan(config: PoolConfig)
An async context manager that ties the pool lifecycle to FastAPI's startup/shutdown.
Example: With FastAPI
from fastapi import FastAPI
from raccoontools_db.fastapi import create_lifespan
from raccoontools_db.pool import PoolConfig, get_pool
config = PoolConfig(conn_info="postgresql://user:pass@localhost:5432/mydb")
app = FastAPI(lifespan=create_lifespan(config))
@app.get("/health")
def health():
pool = get_pool()
with pool.connection() as conn:
conn.execute("SELECT 1")
return {"status": "ok"}
Example: With FastAPI + OpenTelemetry
from fastapi import FastAPI
from raccoontools_db.fastapi import create_lifespan
from raccoontools_db.pool import PoolConfig, get_pool
config = PoolConfig(
conn_info="postgresql://user:pass@localhost:5432/mydb",
use_otel=True,
otel_service_name="my-service",
otel_exporter_endpoint="http://localhost:4318",
)
app = FastAPI(lifespan=create_lifespan(config))
Changelog
Release files for raccoontools-db 1.0.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| raccoontools_db-1.0.1.tar.gz | 8.1 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| raccoontools_db-1.0.1-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 15.3 kB
Release files / raccoontools_db-1.0.1.tar.gz
| Download URL | raccoontools_db-1.0.1.tar.gz |
|---|---|
| Size | 8.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
d28537ee1c2b62b31c7207ffcdb43b40ea6fab49a8c642e0c5fe341609725e6c
|
|
BLAKE2b-256 checksum How to use checksums |
05ccbdf3d6d03033ab09c2045a0ee92ced586469cbe8059cece158d1735b65c9
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.14.5
|
Release files / raccoontools_db-1.0.1-py3-none-any.whl
| Download URL | raccoontools_db-1.0.1-py3-none-any.whl |
|---|---|
| Size | 7.2 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
a5e9f34260d4c2c07dc3f2ceb84902fb61e99883167d7fd73e8cbc505e3f0eef
|
|
BLAKE2b-256 checksum How to use checksums |
ea2a487b8e2183180059c154d107be39519f7468965db0fa8deabbe39681dcbd
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.14.5
|