Skip to main content

SqlAlchemy library

Project description

QuestDB Logo

QuestDB community Slack channel

QuestDB Connect

This repository contains the official implementation of QuestDB's dialect for SQLAlchemy, as well as an engine specification for Apache Superset, using psycopg2 for database connectivity.

The Python module is available here:

PyPi https://pypi.org/project/questdb-connect/

Psycopg2 is a widely used and trusted Python module for connecting to, and working with, QuestDB and other PostgreSQL databases.

SQLAlchemy is a SQL toolkit and ORM library for Python. It provides a high-level API for communicating with relational databases, including schema creation and modification. The ORM layer abstracts away the complexities of the database, allowing developers to work with Python objects instead of raw SQL statements.

Apache Superset is an open-source business intelligence web application that enables users to visualize and explore data through customizable dashboards and reports. It provides a rich set of data visualizations, including charts, tables, and maps.

Requirements

  • Python from 3.9 to 3.11 (superset itself use version 3.9.x)
  • Psycopg2 ('psycopg2-binary~=2.9.6')
  • SQLAlchemy ('SQLAlchemy>=1.4')

You need to install these packages because questdb-connect depends on them. Note that questdb-connect v1.1 is compatible with both SQLAlchemy v1.4 and v2.0 while questdb-connect v1.0 is compatible with SQLAlchemy v1.4 only.

Versions 0.0.X

These are versions released for testing purposes.

Installation

You can install this package using pip:

pip install questdb-connect

SQLAlchemy Sample Usage

Use the QuestDB dialect by specifying it in your SQLAlchemy connection string:

questdb://admin:quest@localhost:8812/main
questdb://admin:quest@host.docker.internal:8812/main

From that point on use standard SQLAlchemy:

import datetime
import os

os.environ.setdefault('SQLALCHEMY_SILENCE_UBER_WARNING', '1')

import questdb_connect.dialect as qdbc
from sqlalchemy import Column, MetaData, create_engine, insert
from sqlalchemy.orm import declarative_base

Base = declarative_base(metadata=MetaData())


class Signal(Base):
    __tablename__ = 'signal'
    __table_args__ = (qdbc.QDBTableEngine('signal', 'ts', qdbc.PartitionBy.HOUR, is_wal=True),)
    source = Column(qdbc.Symbol)
    value = Column(qdbc.Double)
    ts = Column(qdbc.Timestamp, primary_key=True)


def main():
    engine = create_engine('questdb://localhost:8812/main')
    try:
        Base.metadata.create_all(engine)
        with engine.connect() as conn:
            conn.execute(insert(Signal).values(
                source='coconut',
                value=16.88993244,
                ts=datetime.datetime.utcnow()
            ))
    finally:
        if engine:
            engine.dispose()


if __name__ == '__main__':
    main()

Superset Installation

Apache Superset

Follow the instructions available here.

Contributing

This package is open-source, contributions are welcome. If you find a bug or would like to request a feature, please open an issue on the GitHub repository. Have a look at the instructions for developers if you would like to push a PR.

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

questdb_connect-1.1.2.tar.gz (26.5 kB view details)

Uploaded Source

Built Distribution

questdb_connect-1.1.2-py3-none-any.whl (26.2 kB view details)

Uploaded Python 3

File details

Details for the file questdb_connect-1.1.2.tar.gz.

File metadata

  • Download URL: questdb_connect-1.1.2.tar.gz
  • Upload date:
  • Size: 26.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.9.6

File hashes

Hashes for questdb_connect-1.1.2.tar.gz
Algorithm Hash digest
SHA256 f0d1a8c5d13fa568725783520a1a8c7377b17c3c20079d9d7aee7ecb3fbc5553
MD5 e4a39caf854db7bd636d365b57e8f3ca
BLAKE2b-256 59b4686084ded8b4b400c07366c8655bcda53fcca8889c01ea98e46d82a15fd9

See more details on using hashes here.

File details

Details for the file questdb_connect-1.1.2-py3-none-any.whl.

File metadata

File hashes

Hashes for questdb_connect-1.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 19a96e5d7f20719f569c9fbe89be24c8d803d0155e5af16db7e0ca31aa16a5cf
MD5 152b85039b216a89c6aeababda87b4bf
BLAKE2b-256 0d3e38e212579522568590099e72e7f2b8c3e7745ba9392f5ae6a4e6c73fd4cc

See more details on using hashes here.

Supported by

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