Skip to main content

cutedb — Python client

Client for CuteDB, the cute embedded document database. Talks to cutedb-server over HTTP.

Built by Gravicode Studios, led by Kang Fadhil.

pip install cutedb

Standard library only — no dependencies, ever. Python 3.10+.

Use

from decimal import Decimal
from cutedb import CuteClient, CuteQueryError

with CuteClient("http://127.0.0.1:8420") as db:
    orders = db.collection("orders")

    # Decimal is encoded with its exact digits rather than through float, so an invoice total
    # that was exact stays exact.
    orders.insert({"customer": {"name": "Sari"}, "total": Decimal("249000.00")})

    # One request, one lock, one flush — not a loop.
    ids = orders.insert_many([{"n": i} for i in range(10_000)])

    result = db.query(
        "SELECT address.city AS city, SUM(total) AS revenue "
        "FROM orders WHERE status = @status GROUP BY address.city",
        {"status": "selesai"},
    )

    for row in result:                        # results are iterable
        print(row["city"], row["revenue"])

    print(result.plan)                        # how the engine found them

Bind values through parameters rather than building the statement by concatenation: a bound value is used as a value and can never be reinterpreted as syntax.

Query builder

Or don't write the statement at all. The builder binds every value as a parameter for you:

from cutedb import field

q = (db.collection("orders").query()
     .where(field("address.city") == city,
            (field("status") == "paid") | field("total").between(100_000, 500_000))
     .where(field("code").startswith(user_text))       # % and _ in user_text stay literal
     .select("code", "total", buyer="customer.name")
     .order_by("total", desc=True)
     .limit(20).offset(40))

print(q.to_cuteql())   # ... WHERE address.city = @p0 AND (status = @p1 OR total BETWEEN @p2 AND @p3) ...
print(q.parameters)    # {'p0': ..., 'p1': 'paid', ...}
for row in q.run():    # or db.query(q)
    ...

Conditions: == != < <= > >=, is_in/not_in, between/not_between, like/not_like (raw pattern), startswith/endswith/contains (escaped), is_null/is_not_null, is_missing/is_not_missing; combine with & | ~ or and_/or_/not_. Python's & binds tighter than ==, so bracket each comparison. field(...) == None becomes IS NULL.

Field paths, aliases and collection names must be one CuteQL identifier — ASCII letters, digits and _, joined by ., with [n] or [] after a segment, and not a bare keyword — or a ValueError is raised. Values may be str, int, float, Decimal, bool, None, datetime (sent as UTC) or lists of those; anything else is a TypeError.

Notes

  • get, delete and drop_index return None/False for a missing target rather than raising. "It was not there" is an answer, not an error.
  • CuteQueryError carries the server's caret line pointing at the offending character, so printing it is usually the most useful thing to do.
  • The client holds no session state, so one instance is safe to share across threads.

Running the server

dotnet tool install -g CuteDB.Server
cutedb-server shop.cute --port 8420

MIT licensed.

Metadata

Release files for cutedb 2.2.0

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

Source distribution (sdist)

Source distribution for cutedb 2.2.0
File Size Uploaded Provenance
cutedb-2.2.0.tar.gz 18.9 kB Without provenance Details

Built distribution (wheel)

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

Total release size: 33.0 kB

Release files / cutedb-2.2.0.tar.gz

Download URL cutedb-2.2.0.tar.gz
Size 18.9 kB
Tags Source
SHA-256 checksum
How to use checksums
fd7a5f4bcc48ca4375b583f9c9f29105913f7418083077bdb1a7d4a69b08f662
BLAKE2b-256 checksum
How to use checksums
062161106bc4222dc9745f470cfb6ef550a06c5484f70460770cc659848b1bf8
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.10

Release files / cutedb-2.2.0-py3-none-any.whl

Download URL cutedb-2.2.0-py3-none-any.whl
Size 14.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
c8fdb3297ae9d6fe21402908f87c65a44f7de70b10dc5a621581733cc25ab917
BLAKE2b-256 checksum
How to use checksums
df0a1a8551ca65c47c876d52d524adfc751c5dca2cb4a2edec7ebfd328968ac0
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.10

Security for cutedb 2.2.0

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.

Release history Release notifications | RSS feed

This release

2.2.0 This release

2 release files No provenance

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