Console
Run built-in framework commands and write your own with the ./alata CLI.
Every Alata project ships with ./alata, a command-line interface for setup, development, and running your application. Application commands share the same kernel, providers, and container as your HTTP server.
Running commands
Activate your Python environment before running console commands. For the default environment created by ./alata setup:
source .venv/bin/activateList every available command:
./alata listGet help for a specific command, including its arguments and options:
./alata help migrateApplication commands accept global options: -h/--help, -q/--quiet, -V/--version, -n/--no-interaction, and -v/-vv/-vvv for increasing verbosity. Development commands accept their underlying tool's options, described below.
Every ./alata example also works with python alata. Run it from your application's root directory using your environment's Python:
python alata make:migration create_users_tableThe syntax is python alata <command> [arguments]. Here, alata is the project console file and make:migration is the command name. Both forms accept the same commands, arguments, and options, including python alata setup and python alata test.
Without activation, use uv run ./alata <command> or uv run python alata <command>:
uv run python alata migrateDevelopment commands
Install dependencies and run your daily checks from the project console:
./alata setup
source .venv/bin/activate
./alata test
./alata lint
./alata formatsetup uses uv to install the project's dependencies, including the development group, into its project environment. It accepts uv's options, including --active to target an activated virtualenv. test runs pytest; lint and format use Ruff. Pass options and paths directly:
./alata setup --locked
./alata test tests/test_users.py -v
./alata test -k "signup and not slow"
./alata lint app/ --fix
./alata format --checkUse ./alata help test or ./alata test --help to see pytest's options; the same pattern works for the other development commands. Failures return a nonzero exit status, so these commands also work in CI.
./alata clean removes Python bytecode and pytest, Ruff, and mypy caches. It preserves application storage and virtual environments. To manage application cache entries, use the cache API.
For adding or upgrading packages, use uv directly, for example uv add httpx or uv lock --upgrade-package httpx.
Upgrading an existing project
Projects created before v0.11.0.2 need the updated root alata launcher and bootstrap/console.py from the new project template. Preserve any custom launcher changes, add ruff>=0.16.0 to the dev dependency group, and run ./alata setup after updating the framework dependency. You can remove the old Makefile once any custom targets have been accounted for.
For v0.12.0.0, update bootstrap/console.py from the template. Run commands from your chosen Python environment or through uv run ./alata.
Built-in commands
The framework registers this command set out of the box:
| Command | Description |
|---|---|
list | List all available commands. |
help <command> | Display help for a command. |
setup | Install project dependencies with uv. |
test | Run pytest, with optional paths and pytest arguments. |
lint | Check code with Ruff; pass --fix to apply fixes. |
format | Format code with Ruff; pass --check to check without writing. |
clean | Remove development caches. |
serve | Start the HTTP server (--host, --port, --workers, --no-reload). |
migrate | Run all pending database migrations. |
migrate:rollback | Roll back the last batch of migrations. |
migrate:fresh | Drop all tables and re-run every migration from scratch. |
migrate:sync | Record existing migrations as applied without running their up() methods. |
migrate:publish | Copy framework infrastructure migrations (--only, --dry-run, --force). |
migrate:status | Show the status of all migrations. |
schema:dump | Save a schema snapshot; pass --prune to remove applied migration files. |
make:migration <name> | Generate a new migration file. |
make:seeder <name> | Generate a new database seeder class. |
make:provider <name> | Generate a service provider and register it in bootstrap/providers.py. |
db:seed | Seed the database with reference/development data (--seeder to run one). |
db:status | Display connection pool metrics for all database connections. |
up | Bring the application out of maintenance mode. |
down | Put the application into maintenance mode. |
queue:work | Start a queue worker process (--queue, --workers, --reload). |
queue:listen | Run one development worker with code reload (--queue). |
queue:failed | List failed jobs (--limit, default 20). |
queue:retry <uuid> | Re-dispatch a failed job back to the queue (or --all). |
queue:flush | Delete all failed jobs. |
queue:prune-orphans | Prune orphaned background jobs. |
queue:prune-batches | Prune stale job batches (--hours, --unfinished). |
schedule:run | Evaluate and execute all due scheduled events. |
schedule:list | List all registered scheduled events in a table. |
The queue:* family is covered in depth on the queues page, and schedule:* on the scheduling page.
Maintenance mode
./alata down creates a flag file at storage/framework/down. While it exists, the maintenance-mode middleware returns 503 except for configured bypass paths and the scheduler skips due events (unless an event is marked even_in_maintenance_mode()). ./alata up removes the flag. Both commands are idempotent — running them twice just prints a notice.
Writing commands
A command is a class extending Command from alata.console. Declare a name and description, optionally declare arguments and options, and implement handle():
from alata.console import Command, argument, option
class SendReportCommand(Command):
name = "report:send"
description = "Compile and email the daily activity report"
arguments = [
argument("recipient", "Email address to deliver the report to"),
]
options = [
option("days", "d", "Number of days to include", flag=False, default="7"),
option("dry-run", None, "Build the report without sending it", flag=True),
]
def handle(self) -> int:
recipient = self.argument("recipient")
days = int(self.option("days"))
self.line(f"<info>Compiling report for the last {days} day(s)...</info>")
if self.option("dry-run"):
self.line("<comment>Dry run — nothing sent.</comment>")
return 0
reporter = self.container.make("reporter")
reporter.send(recipient, days=days)
self.info(f"Report sent to {recipient}.")
return 0A few things to notice:
- Arguments and options are declared with the
argument()andoption()helpers fromcleo.helpers. Passflag=Truefor boolean switches andflag=Falsewhen the option takes a value;optional=Truemakes an argument optional. - Input is read with
self.argument("name")andself.option("name"). Option values arrive as strings — cast them yourself. - Output goes through
self.line(...)(supports<info>,<comment>,<error>style tags), plus the shortcutsself.info(...)andself.line_error(...). Check verbosity withself.io.is_verbose()/self.io.is_very_verbose()/self.io.is_debug(). - Exit codes are the return value of
handle()— return0for success, non-zero for failure. - The container is available as
self.containeron every command registered with the application, so you can resolve any bound service. See the service container page.
Async work in commands
handle() is synchronous. When a command needs async APIs — the async query builder, the queue broker, redis — wrap the async body with asyncio.run(). This is exactly how the built-in queue:* commands work (see Async and Sync for the full sync/async picture):
import asyncio
from alata.console import Command
class PruneSessionsCommand(Command):
name = "sessions:prune"
description = "Delete expired sessions"
def handle(self) -> int:
return asyncio.run(self.handle_async())
async def handle_async(self) -> int:
import time
from app.models.session import Session
deleted = await Session.where("expires_at", "<", int(time.time())).adelete()
self.info(f"Pruned {deleted} session(s).")
return 0Registering commands
Commands are registered on the application kernel via providers. The scaffolded project ships a dedicated CommandProvider for exactly this:
from alata.support.service_provider import ServiceProvider
from app.console.commands.send_report import SendReportCommand
class CommandProvider(ServiceProvider):
def boot(self):
self.app.add_commands([SendReportCommand])add_commands() accepts classes or pre-built instances. When the console boots, each command is instantiated (if needed) and handed the application container, which is what makes self.container work inside handle().
This is the same mechanism the framework itself uses: the database provider registers the migrate family, and the HTTP provider registers serve, up, and down — commands live next to the provider that owns their services.
Package commands
Installable packages expose commands through the commands() hook on their service provider. The console kernel discovers these automatically:
class Provider(ServiceProvider):
def commands(self) -> list:
return [SnapshotCommand(), PauseCommand()]This is how packages such as taskiq-horizon contribute their horizon:* commands to your CLI without you registering anything.
Overriding option defaults
Every framework command mixes in an override mechanism that lets you change an option's default at registration time — useful when you want a built-in command pre-configured for your project without forking it:
# Register queue:work defaulting to the "emails" queue with 4 workers
self.app.add_commands([QueueWorkCommand(queue="emails", workers="4")])Keyword names map to option names with dashes converted to underscores: an option declared as dry-run is overridden with dry_run=....
Alternatively, a subclass can declare a _<option>_default attribute:
class ProjectQueueWorkCommand(QueueWorkCommand):
_queue_default = "emails"Choosing an environment
Select an environment-specific configuration file for application commands with the global --env flag:
./alata migrate --env testingThis loads .env followed by .env.testing. Configure database connection values in that overlay, as described in configuration.
Generator commands
The make:* commands scaffold files into your project:
make:job <name>— generates aShouldQueuejob inapp/jobs/. Use./alata make:job SendWelcomeEmailor a nested name such asBilling/GenerateInvoice. See queues.make:migration <name>— generates a timestamped migration file. Name it after the change, e.g../alata make:migration create_users_table. See database getting started.make:seeder <name>— generates a seeder class indatabase/seeders/. Either naming style works:user,user_seeder, andUserSeederall produceuser_seeder.pywith aUserSeederclass. See seeding.make:provider <name>— generatesapp/providers/<name>_provider.pyfrom a stub and appends it to thePROVIDERSlist inbootstrap/providers.py, so it boots immediately:
./alata make:provider S3Storage
# CREATED app/providers/s3_storage_provider.py
# REGISTERED 'app.providers.s3_storage_provider' → bootstrap/providers.pymake:provider is idempotent about registration — if the module path is already listed in bootstrap/providers.py, it skips the append instead of duplicating it. It refuses to overwrite an existing provider file.