Skip to main content

pysquril

PYthon Structured URI Query Language. A library for implementing versioned, queryable, and auditable document oriented datastores. Features:

  • Useful for implementing generic document oriented REST APIs
  • Multi-tenancy
  • Enforces uniqueness on records, otherwise schemaless
  • SQL-like query language
  • Ability to apply queries to multiple tables (document sets) simultaneously
  • Audit (with rollback) - who, what, when, why
    • default events: update, delete
    • optional events: create, read
  • PostgreSQL and sqlite database backends

Getting to know pysquril

Use the helper class to run interactive queries on your own input data:

pysquril % poetry run python
>>> from pysquril.interactive import B
>>> B().D([{"x": 0, "y": 1}, {"x": 100, "y": 4, "z": [1,2]}]).Q("select=x,z[1]")
[[0, None], [100, 2]]
>>> B().D([{"x": 0, "y": 1}, {"x": 100, "y": 4, "z": [1,2]}]).Q("select=x,z[1]&order=x.desc")
[[100, 2], [0, None]]
>>> B().D([{"x": 0, "y": 1}, {"x": 100, "y": 4, "z": [1,2]}]).Q("select=x,z[1]&where=y=gt.1")
[[100, 2]]

Example library usage

import sqlite3

from pysquril import SqliteBackend, sqlite_init

# get a connection pool
# most real world usage would use persistent storage
engine = sqlite_init(":memory:")

# instantiate a backend, for a given tenant, and identity
tenant = "tenant1"
backend = SqliteBackend(
    engine,
    schema=tenant,
    requestor="some-user",
    requestor_name="Some Person Name",
)

# add some data
table = "mytable"
backend.table_insert(
    table_name=table,
    data={"saying": "good", "being": ["glad"], "id": 0},
)
backend.table_insert(
    table_name=table,
    data={"saying": "good", "being": ["content", "detached"], "id": 1},
)

# query the data
print(list(backend.table_select(table_name=table, uri_query="select=being")))

# change the second record, with a reason
reason_for_update = "a more accurate description"
backend.table_update(
    table_name=table,
    uri_query=f"set=saying&where=being[0]=eq.'content'&message='{reason_for_update}'",
    data={"saying": "excellent"},
)

# check the audit
print(list(backend.table_select(table_name=f"{table}_audit", uri_query="")))

# restore the data to its prior state
backend.table_restore(
    table_name=table,
    uri_query="restore&primary_key=id",
)

# check that the data is back to its original state
result = list(
    backend.table_select(
        table_name=table,
        uri_query="select=saying&where=being[0]=eq.'content'",
    )
)
assert result[0][0] == "good"

Tests

poetry install
poetry run pytest tests/

For more detailed testing information, including PostgreSQL setup requirements, see tests/README.md.

Generating docs

npm install -g ebnf2railroad
ebnf2railroad pysquril/docs/grammar.ebnf -o pysquril/docs/grammar.html

License

BSD.

Metadata

Release files for pysquril 1.2.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pysquril 1.2.1
File Size Uploaded Provenance Actions
pysquril-1.2.1.tar.gz 28.7 kB Without provenance Details for pysquril-1.2.1.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for pysquril 1.2.1
File Interpreter ABI Platform Actions
pysquril-1.2.1-py3-none-any.whl Python 3 none any Details for pysquril-1.2.1-py3-none-any.whl

Total release size: 62.0 kB

Release files / pysquril-1.2.1.tar.gz

Download URL pysquril-1.2.1.tar.gz
Size 28.7 kB
Tags Source
SHA-256 checksum
How to use checksums
323e723c34ef32521325f7d13787272f1eca2822462c98e0ae9d70dbc9fd3f18
BLAKE2b-256 checksum
How to use checksums
79a1af56c5e3c5ec0fbfe6970a707ab080ab5b1ddf6c304e38c044efa56d1100
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.14

Release files / pysquril-1.2.1-py3-none-any.whl

Download URL pysquril-1.2.1-py3-none-any.whl
Size 33.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
0e191e98f72f6cae59eb4bc6e7be4091bd6408628a59002a6d25ecdfbaba186e
BLAKE2b-256 checksum
How to use checksums
b7de8cd9cdc2efdf4bb7d53e35f7c50923715ad89c49235d390d57984eb89fb1
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.14

Security for pysquril 1.2.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page