This package is currently in alpha stage.
The python client supports both sync and async programs.
The api docs can be found here. The api docs can also be built locally with the following:
cd docs
make htmlSome example code:
from pysirix import sirix_sync, DBType, Insert
from httpx import Client
client = Client(base_url="http://localhost:9443")
sirix = sirix_sync("admin", "admin", client)
db = sirix.database("json-diff", DBType.JSON)
db.create()
resource = db.resource("json-resource")
resource.create(
{
"foo": ["bar", None, 2.33],
"bar": {"hello": "world", "helloo": True},
"baz": "hello",
"tada": [{"foo": "bar"}, {"baz": False}, "boo", {}, []]
}
)
resource.update(4, {"new": "stuff"}, insert=Insert.RIGHT)Node hashes are off by default: resource.create(...) sends hashType=NONE. Enable them explicitly with
resource.create(data, hash_type="ROLLING") (or "POSTORDER"). Be aware that while hashes are enabled a deleted
value can still be confirmed from the hashes of its ancestors. With NONE, JSON containers have no stored subtree
hash aggregates (sdb:hash returns zero for them), so hash-based diff shortcuts require explicit opt-in.
Primitive leaves still derive hashes from their own content, so history and history_embed can detect their
value changes even with NONE; detecting changes within a container through these methods requires stored hashes.
Or with Async Support:
from pysirix import sirix_async, DBType, Insert
from httpx import AsyncClient
import asyncio
async def main():
client = AsyncClient(base_url="http://localhost:9443")
sirix = await sirix_async("admin", "admin", client)
db = sirix.database("json-diff", DBType.JSON)
await db.create()
resource = db.resource("json-resource")
await resource.create(
{
"foo": ["bar", None, 2.33],
"bar": {"hello": "world", "helloo": True},
"baz": "hello",
"tada": [{"foo": "bar"}, {"baz": False}, "boo", {}, []]
}
)
await resource.update(4, {"new": "stuff"}, insert=Insert.RIGHT)
loop = asyncio.get_event_loop()
loop.run_until_complete(asyncio.run(main()))If you are not installing pysirix as part of a project, the preferred install method is to use pipx:
pipx install pysirixIn your home directory, create a folder named pysirix-shell, and create a file named config.json in this folder. This file will hold the configuration for the shell. It should have the following form:
{
"localhost": {
"url": "http://localhost:9443",
"username": "admin",
"timeout": 4
},
"cloud": {
"url": "https://sirix-demo.com:9443",
"username": "administrator"
}
}The timeout field is optional, and defaults to 5 (seconds).