SQLAlchemy TimescaleDB
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)
Metadata
Release files for sqlalchemy-timescaledb 0.4.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| sqlalchemy-timescaledb-0.4.1.tar.gz | 5.1 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| sqlalchemy_timescaledb-0.4.1-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 10.0 kB
Release files / sqlalchemy-timescaledb-0.4.1.tar.gz
| Download URL | sqlalchemy-timescaledb-0.4.1.tar.gz |
|---|---|
| Size | 5.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
43870866c6c951a71a5e83c74580574192baaf833a514eca4855ab8c48d15e0b
|
|
BLAKE2b-256 checksum How to use checksums |
8ef4a06d88278eae468692667a1bf693212f0cb0d23cf1216d32f22cc006861a
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.8.10
|
Release files / sqlalchemy_timescaledb-0.4.1-py3-none-any.whl
| Download URL | sqlalchemy_timescaledb-0.4.1-py3-none-any.whl |
|---|---|
| Size | 4.9 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
c2111a3c8f5f141bbe34a33319926a1427dc6bd8039a2fbbca1965894a1f3416
|
|
BLAKE2b-256 checksum How to use checksums |
c3e42a5c5cdd2b60574547c5b61699826358e6d41005ae72caf71ff1496e36ce
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.8.10
|