A Python connector and ORM for XTDB.
Project description
XTDB Python
A Python connector and ORM for XTDB.
Installation
pip install xtdb
Usage
The following examples assume you have set the XTDB_URI variable in your environment.
To start experimenting, you could use the following setup using Docker:
$ docker run -p 3000:3000 -d juxt/xtdb-standalone-rocksdb:1.21.0
$ export XTDB_URI=http://localhost:3000/_xtdb
Using the ORM
import os
from dataclasses import dataclass
from xtdb.orm import Base
from xtdb.query import Query
from xtdb.session import XTDBSession
@dataclass
class TestEntity(Base):
name: str
@dataclass
class SecondEntity(Base):
age: int
test_entity: TestEntity
session = XTDBSession(os.environ["XTDB_URI"])
entity = TestEntity(name="test")
session.put(entity)
session.commit()
query = Query(TestEntity).where(TestEntity, name="test")
result = session.query(query)
assert result[0].dict() == {"TestEntity/name": "test", "type": "TestEntity", "xt/id": entity.id}
Using only the client
import os
from xtdb.session import XTDBHTTPClient, Operation
client = XTDBHTTPClient(os.environ["XTDB_URI"])
client.submit_transaction([Operation.put({"xt/id": "123", "name": "fred"})])
client.query('{:query {:find [(pull ?e [*])] :where [[ ?e :name "fred" ]]}}')
client.get_entity("123")
Using the CLI tool for querying
Using a query string
$ echo '{:query {:find [(pull ?e [*])] :where [[ ?e :name "fred" ]]}}' | python -m xtdb | jq
[
[
{
"somenil": null,
"name": "fred",
"somedict": {
"c": 3,
"a": "b"
},
"somelist": [
"jeez",
123
],
"xt/id": "123"
}
]
]
or a query in a file:
$ cat query.txt
{:query {:find [(pull ?e [*])] :where [[ ?e :name "fred" ]]}}
$ python -m xtdb < query.txt | jq
[
[
{
"somenil": null,
"name": "fred",
"somedict": {
"c": 3,
"a": "b"
},
"somelist": [
"jeez",
123
],
"xt/id": "123"
}
]
]
Development
Using Poetry, simply run
poetry install
to create your environment. The Makefile has several targets that should make development easier:
$ make utest # Run unit tests
$ make itest # Run integration tests
$ make check # Run all linters
$ make done # Run all of the above
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 xtdb-0.1.0.tar.gz.
File metadata
- Download URL: xtdb-0.1.0.tar.gz
- Upload date:
- Size: 11.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.4.2 CPython/3.9.5 Linux/5.15.0-71-generic
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5a6b4787750ec6dafb8652a308c42f5c19c30a0f0088a5b9c5b8c66c499324ca
|
|
| MD5 |
6182317ed06a4645f10145fc8d7cf396
|
|
| BLAKE2b-256 |
1d83115f76d573638b37473eda633319f5d6f20411994e1713960d22086c3e6c
|
File details
Details for the file xtdb-0.1.0-py3-none-any.whl.
File metadata
- Download URL: xtdb-0.1.0-py3-none-any.whl
- Upload date:
- Size: 12.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.4.2 CPython/3.9.5 Linux/5.15.0-71-generic
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
50a4a863f33b29d0f84407e27d7daab825dd0c1a2dbd3a4cbf904f248fd14d72
|
|
| MD5 |
9e34f13f82d8f2836a442a7308dd48cd
|
|
| BLAKE2b-256 |
3debb5f4c4795678a0c59ab1d8af875fd4cdd3ea8965ecf7f078f3a68f339a55
|