A SQLAlchemy dialect for TimescaleDB
Project description
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)
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
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
Algorithm | Hash digest | |
---|---|---|
SHA256 | 43870866c6c951a71a5e83c74580574192baaf833a514eca4855ab8c48d15e0b |
|
MD5 | 822f962b67500854cc215031273cbe25 |
|
BLAKE2b-256 | 8ef4a06d88278eae468692667a1bf693212f0cb0d23cf1216d32f22cc006861a |
File details
Details for the file sqlalchemy_timescaledb-0.4.1-py3-none-any.whl
.
File metadata
- Download URL: sqlalchemy_timescaledb-0.4.1-py3-none-any.whl
- Upload date:
- Size: 4.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.8.10
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | c2111a3c8f5f141bbe34a33319926a1427dc6bd8039a2fbbca1965894a1f3416 |
|
MD5 | fc8d0a46de1be1adc4f5642c7ecaade6 |
|
BLAKE2b-256 | c3e42a5c5cdd2b60574547c5b61699826358e6d41005ae72caf71ff1496e36ce |