Metadata-Version: 2.5
Name: dryv-author
Version: 0.1.0
Summary: Lightweight typed Python authoring SDK for Dryv
License: Apache-2.0
Requires-Python: >=3.11
Description-Content-Type: text/markdown

# dryv-author

Describe your software once, in Python: schemas, operations, events, policies. The `dryv` CLI compiles it and generates code from it with reusable packs. It mirrors the TypeScript author (`@dryvcode/author`) with Pythonic names, so both produce the same result.

## Install

```bash
uv add --dev dryv-author dryv-compiler     # or: pip install dryv-author dryv-compiler
npm install -g @dryvcode/cli
dryv init --author python --author-path dryv.py --yes
```

Requires Python 3.11+. Create `dryv.py` with the example below (it must expose one module-level `dryv.app(...)`), then run `dryv validate` and `dryv plan`. Run `dryv docs authoring` for tips. This package only describes meaning; it does not generate code or write files.

## Example

```python
from dryv_author import (
    body,
    dryv,
    field,
    http,
    operation,
    path,
    policy,
    prop,
    respond,
    schema,
    scope_binding,
    storage,
)

users = dryv.group("users")
accounts = users.feature("Accounts")  # features are registration scopes

ids = accounts.properties({"Id": prop.string.uuid(), "Name": prop.string()})
models = accounts.schemas(
    {
        "User": schema(
            {
                "id": field(ids.Id).system(),
                "name": field(ids.Name).query(filter="*", sort=True),
            }
        ).facets(storage=storage("users").primary_key("id")),
    }
)

create = operation().role("create").inputs(models.User).outputs(models.User)
create.facets(
    http=http("POST", "/users")
    .input(create.input(0), body())
    .output(create.output(0), respond(201)),
)
accounts.operations({"CreateUser": create})

users.schemas({"AuditEntry": schema({"id": field(ids.Id)})})  # group-owned: no feature

tenant_policy = accounts.policies({"CurrentTenant": policy().provides({"tenantId": ids.Id})})
get_user = (
    operation()
    .role("detail")
    .inputs(id=ids.Id)
    .outputs(models.User)
    .requires(tenant_policy.CurrentTenant)
    .scope(scope_binding(models.User.field("id"), tenant_policy.CurrentTenant, "tenantId"))
)
accounts.operations({"GetUser": get_user})

app = dryv.app("accounts").groups(users)
```

The entrypoint configured in `dryv.yaml` must expose exactly one module-level `dryv.app(...)`. It may import ordinary modules; every registration records the caller's file and line.

## Ownership

Registering through `group.feature("Name")` makes the group the declaration's `group` and the feature its `feature`. Registering directly on the group leaves it group-owned. A declaration can belong to one group and at most one feature.

## API map (TypeScript → Python)

| TypeScript                                            | Python                                                     |
| ----------------------------------------------------- | ---------------------------------------------------------- |
| `property.string.uuid()`                              | `prop.string.uuid()`                                       |
| `property.number.integer({ range: { min: 0 } })`      | `prop.number.integer(range={"min": 0})`                    |
| `field(x).createOnly()`                               | `field(x).create_only()`                                   |
| `.query({ filter: ["notEqual"] })`                    | `.query(filter=["not-equal"])` (`not_equal` also accepted) |
| `expression.and(...)`, `.or(...)`, `.not(...)`        | `expression.all_of(...)`, `.any_of(...)`, `.not_(...)`     |
| `operation().async()`                                 | `operation().async_()`                                     |
| `operationStep`, `waitFor`, `outputFrom`, `inputFrom` | `operation_step`, `wait_for`, `output_from`, `input_from`  |
| `group.policies(ref1, ref2)`                          | same: a mapping registers, refs set scope policies         |
| `.scope({ target, source: { policy, name } })`          | `.scope(scope_binding(target, policy, name))`              |

An Operation scope binds a persisted Schema field to a named value declared in an attached Policy's `provides` context. Use one binding helper per field. The compiler lowers these to the same canonical scope contract as TypeScript and omits the scope when undeclared. Runtime validates declarations; the application remains responsible for Policy evaluation and conjunctive query execution.

## Next

Docs: https://dryv.alidantech.org/docs · Compiler: [`dryv-compiler`](https://pypi.org/project/dryv-compiler/)
