Skip to main content

Provide concise, Pythonic query syntax for SQLAlchemy

Project description

The pythonic_sqlalchemy_query module provides concise, Pythonic query syntax for SQLAlchemy. For example, these two queries produce identical results:

pythonic_query = session.User['jack'].addresses['jack@google.com']
traditional_query = (
    # Ask for the Address...
    session.query(Address).
    # by querying a User named 'jack'...
    select_from(User).filter(User.name == 'jack').
    # then joining this to the Address 'jack@google.com`.
    join(Address).filter(Address.email_address == 'jack@google.com')

Installation

pip install pythonic_sqlalchemy_query

Use with SQLAlchemy

For most cases:

from pythonic_sqlalchemy_query import QueryMakerSession

# Construct an engine as usual.
engine = create_engine(...)
# Create a session aware of this module.
Session = sessionmaker(bind=engine, class_=QueryMakerSession)
session = Session()

# After defining some declarative classes, query away:
for result in session.User['jack'].addresses:
    # Do some processing on result...

The examples provide full, working code.

Use with Flask-SQLAlchemy

For most cases:

from pythonic_sqlalchemy_query.flask import SQLAlchemyPythonicQuery

app = Flask(__name__)
db = SQLAlchemyPythonicQuery(app)

# After defining some declarative classes, query away:
for result in User['jack'].addresses:
    # Do some processing on result...

The examples provide full, working code.

Documentation

See the pythonic_sqlalchemy_query module.

License

This software is distributed under the terms of the MIT license.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for pythonic-sqlalchemy-query, version 1.2.0
Filename, size File type Python version Upload date Hashes
Filename, size pythonic_sqlalchemy_query-1.2.0-py2.py3-none-any.whl (18.1 kB) File type Wheel Python version py2.py3 Upload date Hashes View
Filename, size pythonic_sqlalchemy_query-1.2.0.tar.gz (9.8 kB) File type Source Python version None Upload date Hashes View

Supported by

Pingdom Pingdom Monitoring Google Google Object Storage and Download Analytics Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN DigiCert DigiCert EV certificate StatusPage StatusPage Status page