SDK generation
The SDK plugin generates a typed package from the database's stored definitions. While the database is open, it updates that package in the configured output directory.
The generated code calls the language binding and provides typed access to stored definitions.
Enable sdk in the plugin selection at open, with the output settings below.
Calls without it report the unavailable status.
Query results recursively omit fields containing empty objects or arrays.
Generated rows use None for absent Any fields and empty collections for absent list or dictionary fields.
Null, empty strings, false, zero and array positions stay intact in the returned document.
Native time values
Generated native time fields use
timezone-aware datetime.datetime for timestamps and datetime.timedelta for durations.
Time data must be whole microseconds. Typed decoding rejects precision loss.
Use stardust.instant_from_ticks, instant_to_ticks, duration_from_ticks and duration_to_ticks for native tick conversion.
The explicit tick conversions refuse precision loss and values outside the target range. These conversions perform no native operation.
A native time schema requires one string member, #utc or #dur, and sets additionalProperties to false.
For example, this schema describes a native timestamp:
| Offset (hex) | Bytes (hex) | Meaning |
|---|---|---|
| 00 | 54 52 4F 4E | magic TRON |
| 04 | 4C 74797065 | txt "type" |
| 09 | 6C 737472696E67 | txt "string" |
| 10 | 0F 0A 04000000 0900 0000 | map leaf, size 10: @4 → @9 |
| 1A | 4C 23757463 | txt "#utc" |
| 1F | 0F 0A 1A000000 1000 0000 | map leaf, size 10: @1A → @10 |
| 29 | 4C 23757463 | txt "#utc" |
| 2E | 0E 0D 00 0100 010000 00 29000000 | array leaf, size 13, shift 0, bitmap 0001, count 1 (root): @29 |
| 3B | AC 70726F70657274 696573 | txt "properties" |
| 46 | 0F 0A 3B000000 1F00 0000 | map leaf, size 10: @3B → @1F |
| 50 | 8C 72657175697265 64 | txt "required" |
| 59 | 0F 0A 50000000 2E00 0000 | map leaf, size 10: @50 → @2E |
| 63 | 14 14 616464697469 6F6E616C50726F70 657274696573 | txt "additionalProperties" |
| 79 | 01 | bit false |
| 7A | 0F 0A 63000000 7900 0000 | map leaf, size 10: @63 → @79 |
| 84 | 4C 74797065 | txt "type" |
| 89 | 6C 6F626A656374 | txt "object" |
| 90 | 0F 0A 84000000 8900 0000 | map leaf, size 10: @84 → @89 |
| 9A | 07 16 A8040000 4600 0000 59000000 7A00 0000 90000000 | map branch, size 22, depth 0 (root), slots 3, 5, 7, 10: @46 → @59 → @7A → @90 |
| B0 | 9A000000 00000000 | root → @9A; previous: none |
Use #dur in both places for a duration schema.
Schema fields support lists and stored-schema references.
Scalar time fields also type query filters and rows.
Native time expression results use the same binding types.
An ordinary string schema stays text, including strings with a date-time format.
Native ticks are signed 64-bit counts of 100 ns.
Timestamp ticks count from the Unix epoch in UTC. Duration ticks can be negative.
Settings
Set python.dir to a dedicated package directory.
| Offset (hex) | Bytes (hex) | Meaning |
|---|---|---|
| 00 | 54 52 4F 4E | magic TRON |
| 04 | 3C 646972 | txt "dir" |
| 08 | AC 67656E2F70656F 706C65 | txt "gen/people" |
| 13 | 0F 0A 04000000 0800 0000 | map leaf, size 10: @4 → @8 |
| 1D | 4C 23647572 | txt "#dur" |
| 22 | 7C 5054302E323553 | txt "PT0.25S" |
| 2A | 0F 0A 1D000000 2200 0000 | map leaf, size 10: @1D → @22 |
| 34 | 4C 23647572 | txt "#dur" |
| 39 | 4C 50543253 | txt "PT2S" |
| 3E | 0F 0A 34000000 3900 0000 | map leaf, size 10: @34 → @39 |
| 48 | 8C 6D61785F776169 74 | txt "max_wait" |
| 51 | 0F 0A 48000000 3E00 0000 | map leaf, size 10: @48 → @3E |
| 5B | 8C 6465626F756E63 65 | txt "debounce" |
| 64 | 0F 0A 5B000000 2A00 0000 | map leaf, size 10: @5B → @2A |
| 6E | 6C 707974686F6E | txt "python" |
| 75 | 0F 0A 6E000000 1300 0000 | map leaf, size 10: @6E → @13 |
| 7F | 07 12 05200000 5100 0000 64000000 7500 0000 | map branch, size 18, depth 0 (root), slots 0, 2, 13: @51 → @64 → @75 |
| 91 | 3C 73646B | txt "sdk" |
| 95 | 0F 0A 91000000 7F00 0000 | map leaf, size 10: @91 → @7F |
| 9F | 95000000 00000000 | root → @95; previous: none |
The Python package
The package contains schemas.py, queries.py, mutations.py, and expressions.py.
Each module declares MODEL_FINGERPRINT from the same committed definition snapshot.
Object schemas and operation inputs use standard TypedDict declarations with the original wire keys.
A missing optional schema key stays missing. A present key supplies its value, including zero, false, empty collections, or null.
Object schema references use forward annotations, including recursive references. Non-object references use ordinary host values.
Query inputs distinguish missing keys from null. A missing defaulted parameter keeps its stored default.
A missing filter leaves its variable unbound. A supplied value narrows the rows. Entity filters use stardust.Link.
A variable used only in a predicate remains required. Aggregate and window output variables are not inputs.
A supplied null declared parameter reports missing_parameter.
Query functions return async context managers containing typed async row iterators.
Use async with and async for, including when you stop iteration early.
Query and mutation functions accept page_size, max_cost, as_of and explain as keyword arguments.
Use timedelta for max_cost and subscription waits. Sync takes a native document containing its call options.
The context closes the current page, rows, and query after completion, an exception, or task cancellation.
Inferred object rows use dataclasses. Dynamic rows use ordinary host values.
Await mutation functions to obtain stardust.Commit values.
Each mutation function closes its mutation handle before it returns.
Await expression functions to build stored programs with current macros and obtain decoded host values.
Each expression function closes its program and result document before it returns.
Schema constructors and input mappings remain plain Python values.
This example creates definitions, generates the package, and uses its typed APIs:
import asyncio
from datetime import timedelta
import stardust
async def main():
async with await stardust.open("people.db", plugins={"sdk": {"python": {"dir": "gen/people"}}}) as database:
await stardust.patch_definition_value(database, "schemas", "person", {
"type": "object", "properties": {"name": {"type": "string"}}, "required": ["name"]})
await stardust.patch_definition_value(database, "queries", "names", {
"find": ["?name"], "where": [["schema", "person", "?e"], ["?e", "name", "?name"]]})
await stardust.patch_definition_value(database, "expressions", "double", ["*", "?n", 2])
async with await stardust.parse("{maxWait {#dur PT5S}}", "dust") as sync_options:
await database.sdk().sync(sync_options)
from gen.people import schemas, queries, expressions
await stardust.merge_patch_value(database, {"#_ada": schemas.Person(name="Ada")})
async with queries.names(database) as rows:
names = [row.name async for row in rows]
doubled = await expressions.double(database, {"n": 21})
assert names == ["Ada"]
assert doubled == 42
if __name__ == "__main__":
asyncio.run(main())Activate your license before this example, as described in installation.
Runs
The plugin generates once at open, and again after commits that change definitions. Data commits do not start a run. A run reads all definitions from one committed snapshot.
Each successful render replaces the output directory's contents, including the startup run. See file ownership before choosing an output directory.
Call status to inspect these fields:
| Field | Contents |
|---|---|
enabled | Whether the plugin is enabled |
pending | Whether generation remains |
runs | Run count |
fingerprint | Generation model fingerprint |
outputs | Outputs, each with language, directory and file counts written and removed |
diagnostics | Diagnostics with severity, code, definition type and path, pointer, member, language and message |
failure | Last run failure, with code and message; absent after a successful run |
When to call sync
Generation runs automatically at open and after definition commits, according to the debounce settings. Opening the database or committing definitions can finish before the generated files are ready. Call sync before compiling or reading files that must include those definitions. Applications that can use the files after automatic generation finishes do not need an explicit sync.
The call requests a render immediately, bypassing debounce. It also rebuilds files when definitions have not changed.
Its options accept only the common maxWait option. A timeout leaves the requested run active.
Repeated waits after a timeout join that run. Inspect status when generation reports failed.
Without an output language, sync validates the model inline and writes no files.
File ownership
The plugin owns the entire configured output directory. Every successful render removes its previous contents, including edited files, unrelated files and subdirectories.
Keep application source, database files and other data outside this directory.
Do not edit generated files: the next run replaces your changes.
The plugin retains only its internal .stardust-sdk.lock file between runs.
The plugin renders and validates the package before it removes any files. Rendering errors leave the previous directory contents unchanged. A filesystem error during cleanup or writing can leave the directory empty or partly written. The next successful run clears that partial output and writes a fresh package. Use sync before a build and check its result.
Each file is written through an atomic rename. Rebuilding the whole directory is not atomic.
A destination lock prevents concurrent publication and reports Destination_Busy when another publisher holds it.
Use a separate output directory for each database, with no directory nested inside another output directory.
Cleanup removes symlinks inside the output directory without following them.
The output directory itself and the lock file must not be symlinks.
Directory inspection is limited to 65,536 entries, 64 levels and 16 MiB of stored paths.
An inspection failure leaves the previous contents unchanged.
Operations
| Operation | Returns | Summary |
|---|---|---|
| Sdk.status | document | sdk.status() returns the SDK generator's owned status document. |
| Sdk.sync | none | sdk.sync(options) waits until the SDK generator published the definitions committed before the call. |
Sdk.status
def status(self) -> DocumentParameters
| Parameter | Type | Ownership | Default | Meaning |
|---|---|---|---|---|
self | Sdk | Borrowed for the call | Required | The sdk owner for this operation. Keep it alive during the call. |
Errors
| Status | When |
|---|---|
"unavailable" | the database does not enable the sdk plugin |
"closed" | the database is closed |
"out_of_memory" | native memory is exhausted |
Notes
The document describes generation outputs, diagnostics and the last run: see runs.
Examples
Describe the SDK generator
async with await stardust.parse("{maxWait {#dur PT5S}}", "dust") as sync_options:
await db.sdk().sync(sync_options)
result = (await db.sdk().status())| Offset (hex) | Bytes (hex) | Meaning |
|---|---|---|
| 00 | 54 52 4F 4E | magic TRON |
| 04 | 4C 72756E73 | txt "runs" |
| 09 | 02 01000000000000 00 | i64 1 |
| 12 | 0F 0A 04000000 0900 0000 | map leaf, size 10: @4 → @9 |
| 1C | 7C 656E61626C6564 | txt "enabled" |
| 24 | 09 | bit true |
| 25 | 0F 0A 1C000000 2400 0000 | map leaf, size 10: @1C → @24 |
| 2F | 7C 70656E64696E67 | txt "pending" |
| 37 | 01 | bit false |
| 38 | 0F 0A 2F000000 3700 0000 | map leaf, size 10: @2F → @37 |
| 42 | BC 66696E67657270 72696E74 | txt "fingerprint" |
| 4E | 14 47 736861323536 3A66306531373061 6335346236376230 6639613865343739 3439323261353836 6332316461323931 3062303736366463 6433666562343130 6234313662363165 38 | txt "sha256:f0e170ac54b67b0f9…" |
| 97 | 0F 0A 42000000 4E00 0000 | map leaf, size 10: @42 → @4E |
| A1 | 07 16 280A0000 1200 0000 25000000 3800 0000 97000000 | map branch, size 22, depth 0 (root), slots 3, 5, 9, 11: @12 → @25 → @38 → @97 |
| B7 | A1000000 00000000 | root → @A1; previous: none |
C exports: stardust_db_plugin_call, stardust_result_take_document, stardust_result_error, stardust_result_release
Sdk.sync
def sync(self, options: Document | None = None) -> NoneParameters
| Parameter | Type | Ownership | Default | Meaning |
|---|---|---|---|---|
self | Sdk | Borrowed for the call | Required | The sdk owner for this operation. Keep it alive during the call. |
options | Document | None | Borrowed for the call | None | The borrowed call options, or none. Optional maxWait is a nonnegative native duration, such as {maxWait {#dur PT5S}}. Without it, or with zero, the call checks once. |
Errors
| Status | When |
|---|---|
"invalid_argument" | options is not an object, or an option is invalid, duplicated or unsupported |
"failed" | the plugin's work failed; status describes the failure |
"timeout" | maxWait passed before the work finished |
"unavailable" | the database does not enable the sdk plugin |
"closed" | the database is closed |
Notes
Database close interrupts an active wait. See when to call sync.
Examples
Run the SDK generator and wait for it
async with await stardust.parse("{maxWait {#dur PT5S}}", "dust") as sync_options:
await db.sdk().sync(sync_options)
result = (await db.sdk().status())| Offset (hex) | Bytes (hex) | Meaning |
|---|---|---|
| 00 | 54 52 4F 4E | magic TRON |
| 04 | 4C 72756E73 | txt "runs" |
| 09 | 02 01000000000000 00 | i64 1 |
| 12 | 0F 0A 04000000 0900 0000 | map leaf, size 10: @4 → @9 |
| 1C | 7C 656E61626C6564 | txt "enabled" |
| 24 | 09 | bit true |
| 25 | 0F 0A 1C000000 2400 0000 | map leaf, size 10: @1C → @24 |
| 2F | 7C 70656E64696E67 | txt "pending" |
| 37 | 01 | bit false |
| 38 | 0F 0A 2F000000 3700 0000 | map leaf, size 10: @2F → @37 |
| 42 | BC 66696E67657270 72696E74 | txt "fingerprint" |
| 4E | 14 47 736861323536 3A66306531373061 6335346236376230 6639613865343739 3439323261353836 6332316461323931 3062303736366463 6433666562343130 6234313662363165 38 | txt "sha256:f0e170ac54b67b0f9…" |
| 97 | 0F 0A 42000000 4E00 0000 | map leaf, size 10: @42 → @4E |
| A1 | 07 16 280A0000 1200 0000 25000000 3800 0000 97000000 | map branch, size 22, depth 0 (root), slots 3, 5, 9, 11: @12 → @25 → @38 → @97 |
| B7 | A1000000 00000000 | root → @A1; previous: none |
C exports: stardust_db_plugin_call, stardust_result_take_document, stardust_result_error, stardust_result_release