Skip to main content

Pandas-ORM Integration.

Project description

RedPanda: Pandas & SQLAlchemy

pypi python pytest coverage maintainability

Two great tastes that taste great together.

Use RedPanda to add simple pandas integration into your declarative models.


pip install redpanda

Basic Use

Create a session from a SQLAlchemy engine:

import redpanda

engine = redpanda.create_engine("sqlite://")
# => Engine(sqlite://)

Session = redpanda.orm.sessionmaker(bind=engine)
session = Session()
# => <sqlalchemy.orm.session.Session>


Use the frame() method of RedPanda queries to return a DataFrame representation of the results instead of a collection of models.

query = session.query(MyModel)
# => <redpanda.orm.Query>

# => <pandas.DataFrame>

Querying with Filters

The frame() method that wraps the pandas.read_sql() function into a dialect-agnostic class-method for declarative SQLAlchemy models and can accept the same keyword arguments as pandas.read_sql():

query = session.query(MyModel).filter_by(my_attr="my_val")


Additionally, a within() method is added to SQLAlchemy's InstrumentedAttribute class that accepts a pandas Index object:

index = pandas.period_range("2016-11-01", "2016-11-30", freq="W")
query = session.query(MyModel).filter(MyModel.timestamp.within(index))

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 redpanda, version 0.4.7
Filename, size File type Python version Upload date Hashes
Filename, size redpanda-0.4.7.tar.gz (22.2 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