Skip to main content

SQLAlchemy TimescaleDB

PyPI version Tests codecov Downloads

This is the TimescaleDB dialect driver for SQLAlchemy. Drivers psycopg2 and asyncpg are supported.

Install

$ pip install sqlalchemy-timescaledb

Usage

Adding to table timescaledb_hypertable option allows you to configure the hypertable parameters:

import datetime
from sqlalchemy import create_engine, MetaData
from sqlalchemy import Table, Column, Integer, String, DateTime

engine = create_engine('timescaledb://user:password@host:port/database')
metadata = MetaData()
metadata.bind = engine

Metric = Table(
    'metric', metadata,
    Column('name', String),
    Column('value', Integer),
    Column('timestamp', DateTime(), default=datetime.datetime.now),
    timescaledb_hypertable={
        'time_column_name': 'timestamp'
    }
)

metadata.create_all(engine)

Or using declarative_base style:

import datetime

from sqlalchemy.orm import declarative_base
from sqlalchemy import Column, Float, String, DateTime

Base = declarative_base()

class Metric(Base):
    __table_args__ = ({
        'timescaledb_hypertable': {
            'time_column_name': 'timestamp'
        }
    })

    name = Column(String)
    value = Column(Float)
    timestamp = Column(
        DateTime(), default=datetime.datetime.now, primary_key=True
    )

Parameters

Functions

Timescaledb functions implemented:

first(value, time)

func.first(Metric.value, Metric.timestamp)

last(value, time)

func.last(Metric.value, Metric.timestamp)

Download files

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

Source Distribution

sqlalchemy-timescaledb-0.4.1.tar.gz (5.1 kB view details)

Uploaded Source

Built Distribution

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

sqlalchemy_timescaledb-0.4.1-py3-none-any.whl (4.9 kB view details)

Uploaded Python 3

File details

Details for the file sqlalchemy-timescaledb-0.4.1.tar.gz.

File metadata

  • Download URL: sqlalchemy-timescaledb-0.4.1.tar.gz
  • Upload date:
  • Size: 5.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.8.10

File hashes

Hashes for sqlalchemy-timescaledb-0.4.1.tar.gz
Algorithm Hash digest
SHA256 43870866c6c951a71a5e83c74580574192baaf833a514eca4855ab8c48d15e0b
MD5 822f962b67500854cc215031273cbe25
BLAKE2b-256 8ef4a06d88278eae468692667a1bf693212f0cb0d23cf1216d32f22cc006861a

See more details on using hashes here.

File details

Details for the file sqlalchemy_timescaledb-0.4.1-py3-none-any.whl.

File metadata

File hashes

Hashes for sqlalchemy_timescaledb-0.4.1-py3-none-any.whl
Algorithm Hash digest
SHA256 c2111a3c8f5f141bbe34a33319926a1427dc6bd8039a2fbbca1965894a1f3416
MD5 fc8d0a46de1be1adc4f5642c7ecaade6
BLAKE2b-256 c3e42a5c5cdd2b60574547c5b61699826358e6d41005ae72caf71ff1496e36ce

See more details on using hashes here.

Release history Release notifications | RSS feed

This release

0.4.1 This release

2 files

0.4

2 files

0.3.1

2 files

0.3

2 files

0.2.1

2 files

0.2

2 files

0.1.0

1 file

0.0.1

2 files

Supported by

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