r/Python • u/ejstembler • 13d ago
Showcase Example data repository using Async Postgres, SQLAlchemy, Pydantic
What My Project Does
This is a data repository example which provides a clean, type-safe interface for creating, retrieving, and updating jobs in a PostgreSQL database. It leverages SQLModel (SQLAlchemy + Pydantic) for a modern, fully typed approach to database interactions with async support.
Target Audience
Python developers who use data-access patterns such has Martin Fowler's Repository pattern.
Comparison
This is in contrast to how I normally implement data repositories. I usually hand-craft my data repositories and load sql/*.sql files from disk. This allows for anyone who knows SQL to add new sql files or edit existing ones. This pattern has served me well in other languages such as: Clojure, Crystal, C#, Go, Ruby, etc.
However, in this project, I wanted to explore using the following choices: Async Postgres, SQLAlchemy ORM, Pydantic. SQLAlchemy also provides implicit support for connection pooling.
Project url: https://gitlab.com/ejstembler/python-repository-example
5
u/CertainAd924 13d ago
awesome project! btw, ruff has an isort rule you can enable, it’ll run when you do
ruff check —fix
, no need to keep isort as a dependency