Skip to main content

Python interface for QuestDB

Project description

QuestDB Python Client

This is an open-source Python library for interacting with QuestDB, a high-performance, open-source SQL database designed to process time series data. This client provides an easy-to-use interface for querying and writing data to QuestDB from Python applications.

Features

  • Asynchronous and synchronous query execution
  • Write single or multiple messages to QuestDB
  • Buffer writes for improved performance
  • Convert query results to Pandas DataFrames
  • Type conversion and parsing of query results
  • Support for both HTTP and TCP interfaces

Installation

You can install the QuestDB Python Client using pip:

pip install py-questdb

Quick Start

Here's a simple example to get you started:

import asyncio
from questdb_python_client import QuestDB

async def main():
    # Connect to QuestDB
    db = QuestDB(host="localhost", port=9000)

    # Write some data
    await db.write(
        table_name="sensors",
        symbols={"location": "room1"},
        columns={"temperature": 22.5, "humidity": 60},
        at=datetime.now()
    )

    # Query data
    async for row in db.query("SELECT * FROM sensors ORDER BY timestamp DESC LIMIT 10"):
        print(row)

    # Query data as a DataFrame
    df = await db.query_df("SELECT * FROM sensors WHERE location = 'room1'")
    print(df)

    await db.close()

asyncio.run(main())

Usage

Connecting to QuestDB

from questdb_python_client import QuestDB

# For HTTP interface
db = QuestDB(host="localhost", port=9000)

# For TCP interface
db = QuestDB(host="localhost", port=9009)

Writing Data

# Write a single message
db.write(
    table_name="sensors",
    symbols={"location": "room1"},
    columns={"temperature": 22.5, "humidity": 60},
    at=datetime.now()
)

# Write multiple messages
messages = [
    QuestMessage(table_name="sensors", symbols={"location": "room1"}, columns={"temperature": 22.5}, at=datetime.now()),
    QuestMessage(table_name="sensors", symbols={"location": "room2"}, columns={"temperature": 23.1}, at=datetime.now())
]
db.write_iter(messages)

Querying Data

# Asynchronous query
async for row in db.query("SELECT * FROM sensors WHERE location = 'room1'"):
    print(row)

# Synchronous query
for row in db.query_sync("SELECT * FROM sensors WHERE location = 'room1'"):
    print(row)

# Query as DataFrame
df = await db.query_df("SELECT * FROM sensors WHERE location = 'room1'")
print(df)

License

This project is licensed under the MIT License.

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

py_questdb-0.0.2.tar.gz (4.4 kB view details)

Uploaded Source

Built Distribution

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

py_questdb-0.0.2-py3-none-any.whl (5.3 kB view details)

Uploaded Python 3

File details

Details for the file py_questdb-0.0.2.tar.gz.

File metadata

  • Download URL: py_questdb-0.0.2.tar.gz
  • Upload date:
  • Size: 4.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/5.1.0 CPython/3.12.5

File hashes

Hashes for py_questdb-0.0.2.tar.gz
Algorithm Hash digest
SHA256 02735f6bd74fea9b6aea8b3b36546ee44bb9a4a9bcd44f12176b4e5cc8a91b5e
MD5 ba830137cb2584ba709cd29c6ea4125b
BLAKE2b-256 0dffeb4f676e3b1cd82c0ea0a35d50a546e26cabb8e965ebb4d10319bb230f08

See more details on using hashes here.

File details

Details for the file py_questdb-0.0.2-py3-none-any.whl.

File metadata

  • Download URL: py_questdb-0.0.2-py3-none-any.whl
  • Upload date:
  • Size: 5.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/5.1.0 CPython/3.12.5

File hashes

Hashes for py_questdb-0.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 e3e2357db8a37ad244a13494a790edb00ebd21d44c2d2d4ab1f6c7329b630873
MD5 058ae2885e6300a74be998303511cfa9
BLAKE2b-256 155b38d535ea55f6d29e32b4122def86d5c36f04f9748ea3f6f4aa2a2f37c5a8

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