Skip to main content

sqlalchemy_window

A SQLAlchemy plugin to add support for PostgreSQL WINDOW clause.

NOTE: only supports SQLAlchemy 2.0 and higher.

Example

import sqlalchemy as sa
from sqlalchemy_window import over_window, select, window

metadata = sa.MetaData()
table = sa.Table(
  "prices",
  metadata,
  sa.Column("asset", sa.String(16), primary_key=True),
  sa.Column("ts", sa.DateTime(timezone=True), primary_key=True),
  sa.Column("price", sa.Numeric, nullable=False),
)

w = window("w", partition_by=table.c["asset"], order_by=table.c["ts"], range_=(None, None))

query = select(
  over_window(sa.func.first_value(table.c["price"]), w).label("open"),
  over_window(sa.func.max(table.c["price"]), w).label("high"),
  over_window(sa.func.min(table.c["price"]), w).label("low"),
  over_window(sa.func.last_value(table.c["price"]), w).label("close"),
).where(sa.func.cast(table.c["ts"], sa.Date) == '2023-01-01').window(w)

Development

To setup a development environment run:

python3 -m venv venv
source ./venv/bin/activate
pip install --upgrade pip
pip install -r dev-requirements.txt -e .
pre-commit install

Running tests:

make test
make coverage

A waterfountain1996 project.

Download files

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

Source Distribution

sqlalchemy_window-0.1.0.tar.gz (8.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

sqlalchemy_window-0.1.0-py3-none-any.whl (8.3 kB view details)

Uploaded Python 3

File details

Details for the file sqlalchemy_window-0.1.0.tar.gz.

File metadata

  • Download URL: sqlalchemy_window-0.1.0.tar.gz
  • Upload date:
  • Size: 8.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.7.16

File hashes

Hashes for sqlalchemy_window-0.1.0.tar.gz
Algorithm Hash digest
SHA256 13d661bb14c46d8f4f0fd35d2a08033da847f0e392374c785ea5e5a656d1d5d5
MD5 7c30f560cd665f9521bf1658db48e966
BLAKE2b-256 2d62534612dc83509f1301d7270bab807e8e0d0c39ca8c39d5c7703733e259bb

See more details on using hashes here.

File details

Details for the file sqlalchemy_window-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for sqlalchemy_window-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 558e57351c527641a5f230d4fa1eebfec0e209c2e62a961984effe8a7bdca7a9
MD5 384c2e57f51d30e0998c62ffd99cde32
BLAKE2b-256 716bc94358889fe015a6c84bbc65c5b93840fea7ca7db4a000e4938840d5111c

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page