bakefile.py that holds your tasks:
- Subclass it to share tasks across projects through normal inheritance.
- It extends Pydantic’s
BaseSettings, so configuration is typed class attributes with validation, env-var and.envloading, defaults, and type coercion. - Tasks use the
@command()decorator, same syntax as Typer. ctx.run()executes CLI commands through Python’s subprocess.
Defining tasks with @command
There are two patterns, depending on whether you define the task before or after instantiating the bakebook:- Pattern 1: Before instantiating - Use
@command()on class methods, then access context throughself.ctx. - Pattern 2: After instantiating - Use
@bakebook.command()on standalone functions, then access context throughbakebook.ctx.
@command() accepts all Typer options: name, help, deprecated, and so on.
ctx.run reference.
Configuration with Pydantic settings
Because Bakebook extendsBaseSettings, every class attribute is typed, validated configuration. Values load from environment variables, .env files, or defaults:
self.api_key), so configuration and the tasks that use it live in the same class. Inherited bakebooks inherit configuration too, and subclasses can override individual fields. See Settings for validation, secrets, and getting values out.
Reuse through inheritance
The point of Bakebook being a class: task libraries are just classes you inherit from.Instantiating
Create a bakebook by inheriting fromBakebook or instantiating it directly:
bakefile init or bakefile add-inline.