Skip to content

About

ORM-style Python client for Apache IoTDB REST v2 (Tree model)

Topics

Resources

Code of conduct

Contributing

Security policy

Stars

0 stars

Watchers

0 watching

Forks

Crown IoTDB Client

English | 中文

An ORM-style Python client that maps model classes onto Apache IoTDB and talks to the server through the REST v2 API using the Tree data model.

CI

What it does

  • Maps one Model subclass to one IoTDB device, its ordinary fields to measurements, and its PrimaryKeyField to the time column.
  • Compiles selects, inserts and CREATE TIMESERIES DDL, escapes every parameter, then posts the SQL to POST /rest/v2/query for reads and to POST /rest/v2/nonQuery for writes and DDL.
  • Authenticates with HTTP Basic auth, honours https/verify/timeout, and converts Python datetime values to UTC epoch numbers at the configured timestamp_precision (ms, us or ns).

Compatibility

Component Supported
Apache IoTDB server 2.0.x with the REST v2 service enabled (default port 18080)
Data model Tree (root.<database>.<device>.<measurement>)
Protocol HTTP REST v2: /rest/v2/query and /rest/v2/nonQuery, Basic auth
Python 3.9 and 3.12 (both run in CI)

The only runtime dependency is requests>=2.23.0. The Table data model and transactions spanning several REST requests are not implemented: the server commits each accepted write immediately, so commit() and rollback() cannot undo it.

Build

Requires Python 3.9 or newer and a reachable PyPI index.

git clone https://github.com/iotdb-ecosystem/crown-iotdb-client.git
cd crown-iotdb-client
python -m venv .venv
. .venv/bin/activate
python -m pip install -e .

This project is not published on PyPI; install it from a clone.

Test

python -m pip install -r requirements-dev.txt
python -m pytest -q test_iotdb.py

CI runs exactly that command. test_iotdb.py is fully offline: it replaces the HTTP session with a fake, so no IoTDB server is needed and responses are asserted field by field.

Configuration

IoTDBDatabase(database, **options); database is a Tree path such as root.sg and every model device is created below it.

Option Default Meaning
host localhost IoTDB REST host
port 18080 IoTDB REST port
user / passwd root / root Basic auth credentials
timeout 10 Request timeout in seconds
https False Use https instead of http
verify True TLS certificate verification
timestamp_precision ms ms, us or ns; must match the server
row_limit 10000 Sent with queries when positive; -1 omits it
db = IoTDBDatabase('root.sg', host='127.0.0.1', port=18080,
                   user='root', passwd='root', timeout=10,
                   timestamp_precision='ms', row_limit=-1)

Usage

from crown import IoTDBDatabase, Model, FloatField, PrimaryKeyField

db = IoTDBDatabase('root.sg', host='127.0.0.1', port=18080)

class Sensor(Model):
    temperature = FloatField()
    ts = PrimaryKeyField()

    class Meta:
        database = db
        db_table = 'sensor1'

Sensor.create_table(safe=True)  # connects lazily, creates root.sg first
Sensor.insert(temperature=21.5)
latest = Sensor.select().desc().one()
db.close()

Smoke test against a real server

The unit suite needs no server. To prove the write path end to end, smoke/run.sh starts the pinned apache/iotdb:2.0.12-standalone image with the REST service enabled, runs the live test against it and tears the container down again:

smoke/run.sh
# REST already taken on 18080? use another host port:
IOTDB_REST_PORT=18081 smoke/run.sh

The same script is the smoke job in CI, on workflow_dispatch and weekly. It writes a device, reads the row back and drops the database, so a passing run means the documented API really works against a released server.

Project status

Independent project. Maintained here; contributions and adoption inquiries are welcome.

License

Apache-2.0 - see LICENSE. Derived from the crown ORM by 'machine' (2020, MIT); see NOTICE and licenses/MIT.txt.

About

ORM-style Python client for Apache IoTDB REST v2 (Tree model)

Topics

Resources

Code of conduct

Contributing

Security policy

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages