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
Release history Release notifications | RSS feed
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
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file py_questdb-0.0.1.tar.gz.
File metadata
- Download URL: py_questdb-0.0.1.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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
00ec502e6474ebb5f1a45917e2a727e561245c6759af7cc5e534b6e006803ce6
|
|
| MD5 |
3ea09fa7eef684f584acbed98402c361
|
|
| BLAKE2b-256 |
a1c140d5a5b9e8c27d13ae521d65c1bf4b6a53e680762bfca3d3ab2a835e3c1f
|
File details
Details for the file py_questdb-0.0.1-py3-none-any.whl.
File metadata
- Download URL: py_questdb-0.0.1-py3-none-any.whl
- Upload date:
- Size: 5.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/5.1.0 CPython/3.12.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
bf11eaadfeb1a0a4c44846a261720af52b1208c0dabe367714543ddfd8c897c4
|
|
| MD5 |
092af85b4db1fa9e7abca6d3435423cd
|
|
| BLAKE2b-256 |
0df7f3d41bfaf31d0acfb791afb1c9c182e080dd9238bf17463406693bacbda0
|