Skip to main content

Velocity-Python

A rapid application development library for Python that eliminates boilerplate between your code and your database. Write business logic, not SQL plumbing.

@engine.transaction
def create_order(tx, customer_email, items):
    customer = tx.table("customers").find({"email": customer_email})
    order = tx.table("orders").insert({
        "customer_id": customer["sys_id"],
        "status": "pending",
        "total": sum(i["price"] for i in items),
    })
    tx.table("order_items").insert_many([
        {"order_id": order["sys_id"], "product": i["name"], "price": i["price"]}
        for i in items
    ])
    return order

No connection management, no cursor juggling, no commit/rollback boilerplate. Velocity handles it all.

Python 3.9+ License: MIT


Why Velocity?

Most Python database libraries fall into two camps:

  1. Heavy ORMs (SQLAlchemy, Django ORM) — powerful but complex. You write Python classes that map to tables, manage sessions, deal with migration frameworks, and learn a large API surface before writing your first query.

  2. Raw drivers (psycopg, sqlite3) — full control, but you're writing SQL strings, managing connections, handling cursors, serializing parameters, and building your own transaction/error-handling patterns from scratch.

Velocity occupies the middle ground: a thin, opinionated layer that gives you the convenience of an ORM with the transparency of raw SQL. Tables are just names. Rows are just dicts. Transactions are just context managers. You don't define models — Velocity discovers your schema at runtime and adapts to it.

Design Principles

Principle What It Means
Convention over configuration Sensible defaults everywhere. Override only what you need.
Dicts in, dicts out No custom model classes to learn. Rows are dictionaries.
Transaction-scoped Every operation runs inside an explicit transaction. No surprise autocommit.
Auto-schema Tables and columns are created on the fly in development. Locked down in production.
Driver-agnostic PostgreSQL (primary), MySQL, SQLite, SQL Server — same API surface.
Lambda-native Connection pooling, warm-start reuse, and SQS batch handling built in.

Installation

# Core (no database driver — useful for testing or SQLite)
pip install velocity-python

# PostgreSQL (recommended)
pip install velocity-python[postgres]

# With AWS Lambda support
pip install velocity-python[postgres,aws]

# Everything
pip install velocity-python[all]

Available Extras

Extra Packages Use Case
postgres psycopg[binary]>=3.2.0 PostgreSQL connections
aws boto3, requests Lambda handlers, SQS, Amplify
excel openpyxl Excel export
parquet pyarrow Parquet export
ods odfpy OpenDocument spreadsheet export
templates jinja2 Template rendering
pdf weasyprint HTML → PDF rendering (native Pango/Cairo from the OS or a layer)
http requests HTTP utilities
payment stripe, braintree, xmltodict Stripe and Braintree adapters (Authorize.Net additionally needs authorizenet, installed separately — see docs/payment.md)
mysql mysql-connector-python MySQL connections
sqlserver python-tds SQL Server connections
redis, mongodb, elasticsearch, cassandra, couchbase the matching client NoSQL adapters (docs/nosql.md)
all postgres, aws, excel, templates, http, payment, pdf Typical full install

Requires Python 3.9+ and uses psycopg v3 (not psycopg2) for PostgreSQL.


Quick Start

1. Connect

from velocity.db.servers.postgres import initialize

# From environment variables (DBHost, DBDatabase, DBUser, DBPassword)
engine = initialize()

# Or explicit config
engine = initialize(config={
    "host": "localhost",
    "dbname": "myapp",
    "user": "postgres",
    "password": "secret",
})

2. Use Transactions

# As a decorator (recommended for Lambda handlers)
@engine.transaction
def get_active_users(tx):
    return tx.table("users").select(where={"active": True}).all()

# As a context manager
with engine.transaction() as tx:
    tx.table("users").insert({"name": "Alice", "email": "alice@example.com"})

3. CRUD Operations

@engine.transaction
def demo(tx):
    users = tx.table("users")

    # Insert
    row = users.insert({"name": "Bob", "email": "bob@example.com"})

    # Read
    user = users.row(row["sys_id"])                    # by primary key
    user = users.find({"email": "bob@example.com"})    # by lookup

    # Update
    user["name"] = "Robert"                            # immediate write-through

    # Delete
    users.delete({"sys_id": row["sys_id"]})

4. Bulk Operations

@engine.transaction
def import_customers(tx, records):
    tx.table("customers").insert_many(records)              # multi-row INSERT
    tx.table("customers").upsert_many(records, pk="email")  # INSERT ... ON CONFLICT UPDATE

Documentation

Full documentation is included in the docs/ directory of the source distribution. What changed in each release, and what callers must do before upgrading, is in CHANGELOG.md (Breaking / Deploy ordering / Added / Fixed per version).

Guide File Description
Database ORM docs/database.md Connections, DB_TUNNEL, transactions, tables, rows, results, queries, purge, schema management
Schema Management docs/schema-management.md Runtime auto-heal, declarative ensure_schema(), schema locking, conflict handling
Performance & Optimization docs/performance.md Connection pooling, batch operations, query caching, prepared statements, N+1 prevention, observability
Async Support docs/async.md AsyncTransaction, AsyncTable, AsyncResult, parallel queries with gather()
Configuration Reference docs/configuration.md Every environment variable and SSM config key velocity reads, ssm_config, S3 buckets, engine options
AWS Lambda Handlers docs/aws-handlers.md LambdaHandler, SqsHandler, auth modes, per-record transactions, DataService client boundary, async jobs (JobHandler + job result stores), failure events
AWS Auth Modes docs/AWS_HANDLERS_AUTH.md Cognito auth, public endpoints, webhooks
Deployment docs/deploy.md velocity.aws.deploy: least-privilege IAM, function settings, layers, SQS queue reconcile
Cross-database Mirroring docs/mirroring.md Keep a table identical in two databases (demo ↔ production) by natural key; rwx hooks, FK translation, reconcile
Operations Dashboard docs/operations.md What the automation is doing: schedules, jobs, failures, stuck work, with drill-down (velocity.aws.ops + velocity-react OpsDashboard)
NoSQL Adapters docs/nosql.md Redis, DynamoDB, MongoDB, Elasticsearch, Cassandra, Couchbase behind one capability-honest contract
Payment Processing docs/payment.md Stripe, Braintree and Authorize.Net adapters, processor mirrors, payment lifecycle
Utilities docs/utilities.md Excel/PDF export, data conversion, formatting, timers, email parsing and SMTP sending
Testing Guide docs/TESTING.md Running tests, markers, coverage
Security docs/SECURITY.md Pre-commit hooks, credential scanning
Changelog CHANGELOG.md Per-release breaking changes, deploy ordering, additions and fixes
Improvement Backlog docs/IMPROVEMENT_BACKLOG.md Proposed and deferred library improvements

Architecture

Engine (singleton — survives Lambda warm starts)
├── ConnectionPool (thread-safe, configurable min/max)
└── Transaction (one per request, borrows from pool)
     ├── Table (CRUD, batch ops, schema management)
     │    ├── Row (dict-like, lazy-cache, write-through, batch_update())
     │    └── Result (streaming cursor iteration, transforms)
     ├── View (create, grant, ensure)
     └── Sequence (create, next, current, configure)

Transactions auto-commit on success, auto-rollback on exception. Connections are returned to the pool (or discarded on error). The Engine persists across Lambda invocations, so the pool stays warm.


Multi-Database Support

Database Driver Status
PostgreSQL psycopg[binary]>=3.2.0 Primary, fully tested
MySQL mysql-connector-python Supported
SQLite sqlite3 (stdlib) Supported
SQL Server python-tds Supported
# PostgreSQL
from velocity.db.servers.postgres import initialize
engine = initialize()

# MySQL
from velocity.db.servers.mysql import initialize
engine = initialize()

# SQLite
from velocity.db.servers.sqlite import initialize
engine = initialize(config={"database": "myapp.db"})

# SQL Server
from velocity.db.servers.sqlserver import initialize
engine = initialize()

Project Structure

velocity-python/
├── src/velocity/
│   ├── cache.py                  # Process-level read cache (cache_ttl / memo)
│   ├── logging.py                # Logging setup (JSON in Lambda, text elsewhere)
│   ├── db/
│   │   ├── core/
│   │   │   ├── engine.py         # Engine, ConnectionPool, @engine.transaction
│   │   │   ├── lazy_engine.py    # LazyEngine (build on first use)
│   │   │   ├── transaction.py    # Transaction, query timing, caching, on_commit
│   │   │   ├── table.py          # Table CRUD, batch ops, purge, schema
│   │   │   ├── row.py            # Row (dict-like, write-through, batch_update())
│   │   │   ├── result.py         # Result (cursor wrapper, transforms)
│   │   │   ├── column.py         # Column helpers
│   │   │   ├── database.py       # Database-level operations
│   │   │   ├── jsonproxy.py      # Live list/dict values for JSON columns
│   │   │   ├── async_support.py  # Async versions of core classes
│   │   │   ├── view.py           # View management
│   │   │   ├── sequence.py       # Sequence management
│   │   │   └── decorators.py     # @create_missing, @return_default, retries
│   │   ├── servers/
│   │   │   ├── postgres/         # PostgreSQL dialect + initializer (primary)
│   │   │   ├── mysql/            # MySQL dialect
│   │   │   ├── sqlite/           # SQLite dialect
│   │   │   ├── sqlserver/        # SQL Server dialect
│   │   │   └── tablehelper.py    # Where/column/pointer-join compiler
│   │   ├── fragments.py          # Literal / @@ token handling
│   │   ├── maintenance.py        # DatabaseMaintenance (clone, snapshot, prune)
│   │   ├── migrations.py         # `velocity` CLI: migration runner
│   │   ├── tunnel.py             # DB_TUNNEL support
│   │   └── exceptions.py         # Db* exception hierarchy
│   ├── aws/
│   │   ├── handlers/             # LambdaHandler, SqsHandler, context, mixins
│   │   │   └── mixins/           # DataService, client-input guard, jobs, sessions, web
│   │   ├── capabilities/         # Per-site capability registry and provisioning
│   │   ├── assets/               # Asset store: indexing, references, usage
│   │   ├── deploy/               # Platform-neutral deployment engine
│   │   ├── ssm_config.py         # SSM-backed config (project, then /Global)
│   │   ├── s3.py                 # Presigned URLs, configured buckets
│   │   ├── failures.py           # Failure events (SNS)
│   │   ├── feature_flags.py      # sys_feature_flags cache + mirror
│   │   ├── mirror.py             # Cross-database table mirroring
│   │   ├── job_lifecycle.py      # Job status tracking
│   │   ├── job_results.py        # Job result stores
│   │   ├── dirty_pipeline.py     # sys_dirty / on_dirty pipeline
│   │   ├── ops.py                # Operations dashboard data
│   │   ├── email.py / sms.py     # SES email, SMS
│   │   └── amplify.py, amplify_build.py, blobs.py, facets.py
│   ├── nosql/                    # NoSQL store contract + adapters
│   ├── payment/
│   │   ├── base_adapter.py       # Abstract payment interface
│   │   ├── stripe_adapter.py     # Stripe
│   │   ├── braintree_adapter.py  # Braintree
│   │   ├── authorizenet_adapter.py # Authorize.Net (CIM)
│   │   ├── *_mirror.py           # Processor mirror tables
│   │   └── money.py, charge_rules.py, redact.py
│   └── misc/                     # conv (iconv/oconv), export, format, mail, pdf, timer, ...
├── tests/                        # Unit tests (make test-unit)
├── docs/                         # Detailed documentation
└── pyproject.toml

Development

# Install with dev dependencies
pip install -e ".[dev,test,postgres]"

# Run the unit suite (no database needed)
make test-unit

# Or directly
pytest

# Run with coverage
pytest --cov=velocity --cov-report=html

# Run specific test file
pytest tests/test_connection_pool.py -v

License

MIT

Metadata

Release files for velocity-python 0.2.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for velocity-python 0.2.1
File Size Uploaded
velocity_python-0.2.1.tar.gz 929.4 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for velocity-python 0.2.1
File Interpreter ABI Platform
velocity_python-0.2.1-py3-none-any.whl Python 3 none any Details

Total release size: 1.6 MB

Release files / velocity_python-0.2.1.tar.gz

Download URL velocity_python-0.2.1.tar.gz
Size 929.4 kB
Tags Source
SHA-256 checksum
How to use checksums
d00449e13031c1e6aecc3ade88293c62ee91d0a6f01046b8188b87213cc7f789
BLAKE2b-256 checksum
How to use checksums
8104f347a503dcfa81951b0a75a6c43dfe62606623130a2dab851d0cb7472227
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.11.15

Release files / velocity_python-0.2.1-py3-none-any.whl

Download URL velocity_python-0.2.1-py3-none-any.whl
Size 689.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
0119d45ad6b3a98317517189afb6f0ff935a5677c80f64a2bdec15327859cf05
BLAKE2b-256 checksum
How to use checksums
f2c9ec2ec4f1e5a7202dc7cf95f613f03d816ee0203ad4866f77b5b0df3df127
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.11.15

Release history Release notifications | RSS feed

0.2.2

2 release files

This release

0.2.1 This release

2 release files

0.2.0

2 release files

0.1.99

2 release files

0.1.98

2 release files

0.1.95

2 release files

0.1.94

2 release files

0.1.93

2 release files

0.1.92

2 release files

0.1.91

2 release files

0.1.90

2 release files

0.1.89

2 release files

0.1.85

2 release files

0.1.83

2 release files

0.1.79

2 release files

0.1.78

2 release files

0.1.77

2 release files

0.1.76

2 release files

0.1.75

2 release files

0.1.74

2 release files

0.1.73

2 release files

0.1.72

2 release files

0.1.71

2 release files

0.1.70

2 release files

0.1.69

2 release files

0.1.68

2 release files

0.1.67

2 release files

0.1.66

2 release files

0.1.63

2 release files

0.1.62

2 release files

0.1.61

2 release files

0.1.50

2 release files

0.1.49

2 release files

0.1.48

2 release files

0.1.47

2 release files

0.1.46

2 release files

0.1.45

2 release files

0.1.44

2 release files

0.1.43

2 release files

0.1.42

2 release files

0.1.41

2 release files

0.1.40

2 release files

0.1.39

2 release files

0.1.38

2 release files

0.1.37

2 release files

0.1.36

2 release files

0.1.35

2 release files

0.1.34

2 release files

0.1.33

2 release files

0.1.32

2 release files

0.1.31

2 release files

0.1.30

2 release files

0.1.29

2 release files

0.1.28

2 release files

0.1.24

2 release files

0.1.23

2 release files

0.1.22

2 release files

0.1.21

2 release files

0.1.20

2 release files

0.1.18

2 release files

0.1.17

2 release files

0.1.16

2 release files

0.1.15

2 release files

0.1.14

2 release files

0.1.13

2 release files

0.1.12

2 release files

0.1.11

2 release files

0.1.10

2 release files

0.1.9

2 release files

0.1.8

2 release files

0.1.7

2 release files

0.1.5

2 release files

0.1.4

2 release files

0.1.3

2 release files

0.1.2

2 release files

0.1.1

2 release files

0.0.88

2 release files

0.0.87

2 release files

0.0.86

2 release files

0.0.78

2 release files

0.0.77

2 release files

0.0.76

2 release files

0.0.75

2 release files

0.0.74

2 release files

0.0.73

2 release files

0.0.72

2 release files

0.0.70

2 release files

0.0.69

2 release files

0.0.68

2 release files

0.0.67

2 release files

0.0.66

2 release files

0.0.65

2 release files

0.0.64

2 release files

0.0.35

2 release files

0.0.34

2 release files

0.0.33

2 release files

0.0.32

2 release files

0.0.31

2 release files

0.0.18

2 release files

0.0.15

2 release files

0.0.14

2 release files

0.0.13

2 release files

0.0.12

2 release files

0.0.11

2 release files

0.0.9

2 release files

0.0.8

2 release files

0.0.7

2 release files

0.0.6

2 release files

0.0.5

2 release files

0.0.4

2 release files

0.0.3

2 release files

0.0.2

2 release files

0.0.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page