Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/amancevice/redpanda
Pandas-SQLAlchemy integration
https://github.com/amancevice/redpanda
pandas python sqlalchemy
Last synced: about 2 months ago
JSON representation
Pandas-SQLAlchemy integration
- Host: GitHub
- URL: https://github.com/amancevice/redpanda
- Owner: amancevice
- License: mit
- Created: 2015-10-03T14:45:09.000Z (about 9 years ago)
- Default Branch: main
- Last Pushed: 2024-03-10T15:32:45.000Z (10 months ago)
- Last Synced: 2024-10-10T04:07:55.547Z (2 months ago)
- Topics: pandas, python, sqlalchemy
- Language: Python
- Size: 253 KB
- Stars: 28
- Watchers: 5
- Forks: 4
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# RedPanda: Pandas & SQLAlchemy
![pypi](https://img.shields.io/pypi/v/redpanda?color=yellow&logo=python&logoColor=eee&style=flat-square)
![python](https://img.shields.io/pypi/pyversions/redpanda?logo=python&logoColor=eee&style=flat-square)
[![pytest](https://img.shields.io/github/actions/workflow/status/amancevice/redpanda/pytest.yml?logo=github&style=flat-square)](https://github.com/amancevice/redpanda/actions/workflows/pytest.yml)
[![coverage](https://img.shields.io/codeclimate/coverage/amancevice/redpanda?logo=code-climate&style=flat-square)](https://codeclimate.com/github/amancevice/redpanda/test_coverage)
[![maintainability](https://img.shields.io/codeclimate/maintainability/amancevice/redpanda?logo=code-climate&style=flat-square)](https://codeclimate.com/github/amancevice/redpanda/maintainability)Two great tastes that taste great together.
Use RedPanda to add simple pandas integration into your declarative models.
## Installation
```bash
pip install redpanda
```## Basic Use
Create a session from a SQLAlchemy engine:
```python
import redpandaengine = redpanda.create_engine("sqlite://")
# => Engine(sqlite://)Session = redpanda.orm.sessionmaker(bind=engine)
session = Session()
# =>
```## Querying
Use the `frame()` method of RedPanda queries to return a DataFrame representation of the results instead of a collection of models.
```python
query = session.query(MyModel)
# =>query.frame()
# =>
```### 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()`:
```python
query = session.query(MyModel).filter_by(my_attr="my_val")query.frame(index_col="time")
```Additionally, a `within()` method is added to SQLAlchemy's InstrumentedAttribute class that accepts a pandas Index object:
```python
index = pandas.period_range("2016-11-01", "2016-11-30", freq="W")
query = session.query(MyModel).filter(MyModel.timestamp.within(index))
```