Reference¶
Config schema¶
Each target has its own pydantic schema that its config files parse into:
be–ProjectConfig(covered in detail below).be_root–RootConfig(be_root config schema).fe–ProjectConfig(fe config schema).fe_root–RootConfig(fe_root config schema).
The classes below correspond directly to the fields you write in
the matching .jsonnet / .json file for that target.
be config schema¶
Field types¶
The type field on FieldSpec accepts:
Type |
Python annotation |
Used in |
Notes |
|---|---|---|---|
|
|
request/response schemas, pk |
Default for primary keys. |
|
|
schemas, action params |
|
|
|
schemas |
Added |
|
|
schemas, pk |
|
|
|
schemas |
|
|
|
schemas |
|
|
|
schemas |
|
|
|
schemas |
|
|
|
schemas |
|
|
generated sub-schema class |
read-op schemas ( |
Dumps a related model inline. Requires |
be_root config schema¶
fe config schema¶
fe_root config schema¶
Built-in operations¶
Every built-in operation is registered under its target’s own
entry-point group in pyproject.toml: be.operations for the
be target, be_root.operations for be_root, and so on.
See Usage for what each one generates and Extending codegen
for the operation protocol.
The table below covers be’s built-in ops; be_root, fe,
and fe_root each ship a single project-scope RootScaffold /
OpenApiTsConfig op (see be_root config schema, fe config schema,
fe_root config schema for the configs that drive them).
Name |
Module |
Scope |
Description |
|---|---|---|---|
|
|
project |
Two project-scope ops live here. |
|
|
resource |
The five CRUD endpoints. Each op lives in its own module alongside the FastAPI renderer for its output. |
|
|
resource |
Custom action endpoints: |
|
|
resource |
Cross-cutting augmenter. Appends |
|
|
app |
Emits |
|
|
project |
Multi-app projects only. Emits the top-level
|
Generated file layout¶
The table below summarises every file be can produce. Paths are
relative to the config’s package_prefix directory under
--prefix-path (by default _generated/ under the current
directory). {module} is the app’s module config field.
{name} is the lowercase, snake-cased model name.
Path |
Produced by |
Overwrite |
|---|---|---|
|
|
Yes |
|
|
Yes |
|
|
Yes |
|
|
Yes |
|
|
Yes |
|
|
Yes |
|
|
Yes |
|
CRUD + |
Yes |
|
|
Yes |
|
CRUD + |
Yes |
|
|
Yes |
Every file is overwritten on every generation run.
codegen API¶
Targets¶
Engine¶
Operations¶
- operation(name, *, scope, requires=None, after_children=False, dispatch_on=None, registry=None, match_value=None)[source]¶
- Return type:
- class OperationMeta(name, scope, requires=(), after_children=False, dispatch_on=None, match_value=None)[source]¶
- class EmptyOptions(**data)[source]¶
- model_config: ClassVar[ConfigDict] = {}¶
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
Scopes¶
- codegen.scope.PROJECT¶
The root scope – always present in every generation run.
Typed outputs¶
Every operation’s build method returns instances of the types
below. Framework-agnostic types live in codegen.outputs;
FastAPI-specific output dataclasses live in
be.operations.types.
Render registry¶
- class RenderRegistry(_entries=<factory>)[source]¶
- class RenderCtx(env, config, package_prefix='', language='', target_name='', store=<factory>, instance_id=<factory>)[source]¶
- class FileFragment(path, template=None, context=<factory>, imports=<factory>, if_exists='overwrite', executable=False, banner=True, id='')[source]¶
- class SnippetFragment(parent, slot, template=None, context=<factory>, value=None, imports=<factory>, id=None)[source]¶
- class Fragment¶
Type alias.
Type aliases are created through the type statement:
type Alias = int
In this example, Alias and int will be treated equivalently by static type checkers.
At runtime, Alias is an instance of TypeAliasType. The __name__ attribute holds the name of the type alias. The value of the type alias is stored in the __value__ attribute. It is evaluated lazily, so the value is computed only if the attribute is accessed.
Type aliases can also be generic:
type ListOrSet[T] = list[T] | set[T]
In this case, the type parameters of the alias are stored in the __type_params__ attribute.
See PEP 695 for more information.
- codegen.render.registry¶
Process-wide
RenderRegistrypopulated at import time.
Output¶
Naming and imports¶
Jinja environment¶
Stdlib reference¶
The following .libsonnet files ship inside the be package and
are importable from any config file using the be/ prefix.
be/auth/jwt.libsonnet¶
Configures JWT authentication.
local auth = import 'be/auth/jwt.libsonnet';
auth.jwt({
secret_env: "JWT_SECRET",
algorithm: "HS256",
token_url: "/auth/token",
exclude_paths: ["/docs", "/openapi.json", "/health"],
verify_credentials_fn: "myapp.auth.verify_credentials",
})
To supply a custom get_current_user dependency instead of the
generated JWT flow, set get_current_user_fn to a dotted import
path. In that case verify_credentials_fn is not required.
be/db/databases.libsonnet¶
Configures async PostgreSQL connections.
local db = import 'be/db/databases.libsonnet';
db.postgres("primary", {
url_env: "DATABASE_URL",
default: true,
echo: false,
pool_size: 5,
max_overflow: 10,
pool_timeout: 30,
pool_recycle: -1,
pool_pre_ping: true,
})
Resources that omit db_key use the database with default: true.
pgqueuer integration¶
be does not scaffold pgqueuer wiring. See Background tasks (pgqueuer) for
the full guide — the two helpers in ingot.queue
(ingot.queue.get_queue() for transactional-outbox enqueue,
ingot.queue.open_worker_driver() for the SQLAlchemy→asyncpg
DSN bridge), the worker-factory pattern, and how to run the
worker with pgqueuer’s own CLI.