Django Sabridge
A Python library that provides SQLAlchemy expression language access to existing Django models for building complex, database-agnostic queries.

What it is
django-sabridge is a specialized bridge library for developers working with Django who need to execute more complex database queries than the standard ORM allows. It enables access to Django models through SQLAlchemy's powerful Expression Language, allowing for programmatic generation of sophisticated SQL queries without losing database independence.
The main feature of django-sabridge is its Bridge class, which returns a SQLAlchemy Table object for any given Django model. This allows developers to leverage SQLAlchemy's query-building engine to perform complex joins, filters, and aggregations on their existing Django model data, all while maintaining the application's database portability.
This tool is specifically designed for Django developers who have hit the limitations of the standard ORM but want to avoid vendor lock-in and the security challenges of hand-writing SQL. It provides an intermediate solution that doesn't replace Django's ORM but complements it for advanced querying scenarios.
While not a full ORM replacement, django-sabridge addresses a specific niche in the Django ecosystem by allowing developers to build extremely complex queries programmatically while retaining the benefits of both Django's model management and SQLAlchemy's query rendering capabilities.
This description was generated by AI from the site's public content and may contain errors.
What you can do there
- SQLAlchemy access to Django models
- Database-agnostic query building
- Programmatic SQL generation
- Documentation and API reference
- Open source library development
Who it's for
Django developers needing complex database queries without vendor lock-in
Frequently asked questions about django-sabridge.readthedocs.io
›What is django-sabridge used for?
It allows Django developers to use SQLAlchemy's expression language to build complex, database-agnostic queries against their existing Django models without replacing the Django ORM.
›How does django-sabridge work with Django transactions?
It doesn't reuse Django's database connection, so data modifications made by either Django or SQLAlchemy won't be visible to the other until the transaction is committed.
›What are the performance considerations with django-sabridge?
It uses SQLAlchemy's reflection to discover model schemas, so users should ensure this introspection fits within their performance requirements.
›Can I use django-sabridge in production applications?
Yes, but developers should be aware of the transaction isolation caveats and performance implications of schema reflection.
›How do I get started with django-sabridge?
Import the Bridge class, initialize it, and then access your Django models as SQLAlchemy tables using bridge[YourModelClass].
›Does django-sabridge replace Django's ORM?
No, it works alongside Django's ORM, providing SQLAlchemy access specifically for complex query scenarios where the standard ORM is insufficient.
›What testing considerations are there when using django-sabridge?
Tests using both Django and SQLAlchemy must use TransactionTestCase instead of TestCase due to transaction isolation issues.
