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.
- Maps one
Modelsubclass to one IoTDB device, its ordinary fields to measurements, and itsPrimaryKeyFieldto thetimecolumn. - Compiles selects, inserts and
CREATE TIMESERIESDDL, escapes every parameter, then posts the SQL toPOST /rest/v2/queryfor reads and toPOST /rest/v2/nonQueryfor writes and DDL. - Authenticates with HTTP Basic auth, honours
https/verify/timeout, and converts Pythondatetimevalues to UTC epoch numbers at the configuredtimestamp_precision(ms,usorns).
| 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.
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.
python -m pip install -r requirements-dev.txt
python -m pytest -q test_iotdb.pyCI 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.
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)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()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.shThe 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.
Independent project. Maintained here; contributions and adoption inquiries are welcome.
Apache-2.0 - see LICENSE. Derived from the crown ORM by 'machine' (2020, MIT); see NOTICE and licenses/MIT.txt.