Skip to main content

📦 sqlalchemy-repository

Django-like Repository & QuerySet layer for SQLAlchemy (async-first)

sqlalchemy-repository brings a familiar, expressive, and powerful QuerySet API on top of SQLAlchemy, inspired by Django ORM — but designed for modern async Python.

It helps you write cleaner, composable database logic with support for:

  • 🔍 Django-style filtering (Q, F)
  • 🔗 Relation traversal via __ syntax
  • 📊 Aggregations (Count, Min, Max, etc.)
  • ⚡ Async-first design
  • 🧱 Repository patterns
  • 🧠 Type-safe and extensible

🚀 Features

  • QuerySet API

    await repo.objects.filter(Q(price__gt=100) & Q(active=True)).all()
    
  • Django-style lookups

    Q(name__icontains="bmw")
    Q(category__parent__id=1)
    
  • F expressions (field references)

    await repo.objects.update(price=F("price") * 1.1)
    
  • Aggregations

    await repo.objects.annotate(total=Count("id"), max_price=Max("price"))
    
  • Annotations

    await repo.objects.annotate(total=F("qty") * F("unit_price"))
    
  • Async support (SQLAlchemy 2.0+)

  • Composable query expressions

  • Repository pattern abstraction


📦 Installation

pip install sqlalchemy-repository

⚙️ Requirements

  • Python 3.11+
  • SQLAlchemy 2.0+

🏗 Basic Usage

Define repository

from sqlalchemy_repository import BaseRepository

class ProductRepository(BaseRepository[Product]):
    model = Product

Querying

products = await repo.objects.filter(
    Q(price__gt=100),
    Q(category__name="Engine")
).order_by("-price").all()

Get single object

product = await repo.objects.get(id=1)

Create

await repo.create(
    name="Brake Pad",
    price=50
)

Update with F expressions

await repo.objects.filter(id=1).update(
    price=F("price") * 1.2
)

Delete

await repo.objects.filter(price__lt=10).delete()

🔗 Relationships via __

await repo.objects.filter(
    category__parent__name="Auto Parts"
)

No manual joins needed — handled internally.


🔍 Q Expressions

from sqlalchemy_repository import Q

query = Q(price__gt=100) & (Q(stock__lt=5) | Q(discount=True))

await repo.objects.filter(query).all()

🧮 Aggregations

from sqlalchemy_repository import Count, Max

result = await repo.objects.annotate(
    total=Count("id"),
    max_price=Max("price")
)

🏷 Annotations

qs = repo.objects.annotate(
    total_price=F("quantity") * F("unit_price")
)

data = await qs.all()

🛠 Development

Install dev dependencies:

pip install -e .[dev]

Run linters:

ruff check .
mypy .

🤝 Contributing

Contributions are welcome.

  1. Fork the repo
  2. Create a feature branch
  3. Write tests
  4. Open a PR

📄 License

MIT License

Release files for sqlalchemy-repository 1.1.4

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

Source distribution (sdist)

Source distribution for sqlalchemy-repository 1.1.4
File Size Uploaded
sqlalchemy_repository-1.1.4.tar.gz 11.6 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for sqlalchemy-repository 1.1.4
File Interpreter ABI Platform
sqlalchemy_repository-1.1.4-py3-none-any.whl Python 3 none any Details

Total release size: 27.5 kB

Release files / sqlalchemy_repository-1.1.4.tar.gz

Download URL sqlalchemy_repository-1.1.4.tar.gz
Size 11.6 kB
Tags Source
SHA-256 checksum
How to use checksums
5e630948e8eb262f6719c092d8fb4ad65229eca4a74c6494b1595a39c8cf2d13
BLAKE2b-256 checksum
How to use checksums
2f8c7019e42f0cde32af487121ae0f58699278278270c848b38851bf03452e97
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.12

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on May 7, 2026.

Transparency log

Release files / sqlalchemy_repository-1.1.4-py3-none-any.whl

Download URL sqlalchemy_repository-1.1.4-py3-none-any.whl
Size 15.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
b9b3a24f02d0bbe9f9fe0df1c7ffebe2209f54a47d05219f7cc7ac99a028ab4c
BLAKE2b-256 checksum
How to use checksums
d3861fc90ec73016e22be16d27c1024f5a934427f9da465a1061917dfde9c789
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.12

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on May 7, 2026.

Transparency log

Release history Release notifications | RSS feed

This release

1.1.4 This release

2 release files

1.1.3

2 release files

1.1.2

2 release files

1.1.1

2 release files

1.1.0

2 release files

1.0.1

2 release files

1.0.0

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