alata.
Digging Deeper

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/activate

List every available command:

./alata list

Get help for a specific command, including its arguments and options:

./alata help migrate

Application 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_table

The 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 migrate

Development commands

Install dependencies and run your daily checks from the project console:

./alata setup
source .venv/bin/activate
./alata test
./alata lint
./alata format

setup 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 --check

Use ./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:

CommandDescription
listList all available commands.
help <command>Display help for a command.
setupInstall project dependencies with uv.
testRun pytest, with optional paths and pytest arguments.
lintCheck code with Ruff; pass --fix to apply fixes.
formatFormat code with Ruff; pass --check to check without writing.
cleanRemove development caches.
serveStart the HTTP server (--host, --port, --workers, --no-reload).
migrateRun all pending database migrations.
migrate:rollbackRoll back the last batch of migrations.
migrate:freshDrop all tables and re-run every migration from scratch.
migrate:syncRecord existing migrations as applied without running their up() methods.
migrate:publishCopy framework infrastructure migrations (--only, --dry-run, --force).
migrate:statusShow the status of all migrations.
schema:dumpSave 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:seedSeed the database with reference/development data (--seeder to run one).
db:statusDisplay connection pool metrics for all database connections.
upBring the application out of maintenance mode.
downPut the application into maintenance mode.
queue:workStart a queue worker process (--queue, --workers, --reload).
queue:listenRun one development worker with code reload (--queue).
queue:failedList failed jobs (--limit, default 20).
queue:retry <uuid>Re-dispatch a failed job back to the queue (or --all).
queue:flushDelete all failed jobs.
queue:prune-orphansPrune orphaned background jobs.
queue:prune-batchesPrune stale job batches (--hours, --unfinished).
schedule:runEvaluate and execute all due scheduled events.
schedule:listList 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():

app/console/commands/send_report.py
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 0

A few things to notice:

  • Arguments and options are declared with the argument() and option() helpers from cleo.helpers. Pass flag=True for boolean switches and flag=False when the option takes a value; optional=True makes an argument optional.
  • Input is read with self.argument("name") and self.option("name"). Option values arrive as strings — cast them yourself.
  • Output goes through self.line(...) (supports <info>, <comment>, <error> style tags), plus the shortcuts self.info(...) and self.line_error(...). Check verbosity with self.io.is_verbose() / self.io.is_very_verbose() / self.io.is_debug().
  • Exit codes are the return value of handle() — return 0 for success, non-zero for failure.
  • The container is available as self.container on 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):

app/console/commands/prune_sessions.py
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 0

Registering commands

Commands are registered on the application kernel via providers. The scaffolded project ships a dedicated CommandProvider for exactly this:

app/providers/command_provider.py
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 testing

This 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 a ShouldQueue job in app/jobs/. Use ./alata make:job SendWelcomeEmail or a nested name such as Billing/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 in database/seeders/. Either naming style works: user, user_seeder, and UserSeeder all produce user_seeder.py with a UserSeeder class. See seeding.
  • make:provider <name> — generates app/providers/<name>_provider.py from a stub and appends it to the PROVIDERS list in bootstrap/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.py

make: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.

On this page