SQLAlchemy-Utils
A grab-bag of extra column types, aggregates, and utility functions for SQLAlchemy models.
Repository Health
Technical Analysis
SQLAlchemy-Utils extends SQLAlchemy with a large collection of custom column types (email, phone number, URL, currency, color, IP address, encrypted, JSON, UUID, and more), model helper functions (aggregated columns, generic relationships, view support), and standalone utilities for common patterns that SQLAlchemy’s core doesn’t cover out of the box, such as creating/dropping test databases, force-cascading deletes, and coercing scalar values. It’s built on top of SQLAlchemy 2.0+ and is widely used as a companion library rather than a replacement for the ORM itself.
What You Get
- Dozens of custom SQLAlchemy column types: EmailType, PhoneNumberType, URLType, ColorType, CurrencyType, IPAddressType, EncryptedType, JSONType, UUIDType, PasswordType, and more
- Aggregated column support that keeps a denormalized aggregate (count, sum, etc.) in sync with related rows
- Utility functions for database lifecycle in tests: create_database(), drop_database(), database_exists()
- Generic relationship and view helpers for modeling polymorphic associations and SQL views as ORM entities
Common Use Cases
- Storing and validating structured data (emails, phone numbers, currencies, colors) directly as typed SQLAlchemy columns instead of plain strings
- Spinning up and tearing down throwaway test databases in a pytest suite via create_database()/drop_database()
- Maintaining a denormalized aggregate column (e.g. a running comment count) automatically as related rows change
- Encrypting sensitive column values at rest with EncryptedType while keeping normal ORM query ergonomics
Under The Hood
Architecture: The library is a flat collection of independent modules rather than a single cohesive subsystem: sqlalchemy_utils/types/*.py each define one custom column type by subclassing SQLAlchemy’s TypeDecorator and implementing process_bind_param/process_result_value, while sqlalchemy_utils/functions/ holds standalone helpers (database creation, cascading deletes) and aggregates.py/generic.py/observer.py/view.py add SQLAlchemy event-listener-based behaviors (e.g. aggregates.py hooks into the ORM’s mapper/session events to recompute denormalized columns on flush). Tech Stack: Pure Python 3.10+ built on SQLAlchemy>=2.0 as its only hard dependency, with a long tail of optional extras (Babel, arrow, pendulum, phonenumbers, passlib, colour, intervals) gated behind pip extras so users only pull in what a given type needs. Code Quality: A substantial tests/ directory (110+ files) mirrors the module layout closely, with dedicated test modules per column type and per utility function, run against multiple real database backends (psycopg2, pymysql, pyodbc) rather than mocks, reflecting the library’s cross-dialect compatibility goals. API Design: Types and functions are designed as drop-in replacements for stock SQLAlchemy Column type arguments (e.g. Column(EmailType) instead of Column(String)), so adopting one feature requires no restructuring of existing models, though the sheer breadth of the API surface (dozens of types/functions) means discoverability relies heavily on the documentation site.
Used by 7 apps in this directory
agenta
Developer Tools · Devops · AI Development
The open-source LLMOps platform unifying prompt engineering, evaluation, and observability for teams building reliable LLM applications.
Apache Airflow
Data Engineering
Define, schedule, and monitor complex data workflows as Python code — with a powerful UI, 80+ provider integrations, and battle-tested scalability across thousands of production deployments.
Keep
Devops · Automation · Monitoring
The open-source AIOps and alert management platform that unifies 130+ monitoring tools into a single pane of glass with AI-powered correlation, deduplication, and workflow automation.
knowhere
AI Development · Developer Tools
Transform messy, unstructured documents into persistent, navigable memory that AI agents can actually use.
LearnHouse
Learning Management · CMS
Open-source LMS with AI tutoring, real-time collaboration boards, live code execution, and built-in course monetization — self-hosted in minutes.
Polar
Ecommerce · Developer Tools · Invoicing Finance
Open source payments infrastructure that turns software into a business — subscriptions, usage-based billing, digital products, and merchant-of-record compliance in one platform.
Redash
Analytics · Data Engineering
Redash lets anyone connect to 35+ SQL and NoSQL data sources, write a query in the browser, and turn the result into a shared dashboard — no separate BI suite required.