Command-Line Interface (CLI)¶
Ushka comes with a handy command-line interface (CLI) to help you with common development tasks. You can access it through the ushka command.
Ushka CLI
Options:
--help Show this message and exit.
Commands:
db Database commands
dev Starts the development server with auto-reload
new Creates a new Ushka project
routes Route management
run Starts the production server
ushka new my_awesome_project🚀 Creating new Ushka project: my_awesome_project
✅ Project 'my_awesome_project' created successfully!
cd my_awesome_projectushka devINFO: Starting Ushka server in development mode on http://127.0.0.1:8000
INFO: Auto-reload is enabled.
Creating a New Project¶
The new command is the easiest way to start a new Ushka project. It creates a new directory with a recommended project structure, including a sample application, configuration file, and templates.
This will create a my_project directory with everything you need to get started.
Development Server (dev)¶
The dev command starts the development server. This command is designed for local development and includes features like auto-reloading when you change your code.
This will start a Uvicorn server on http://127.0.0.1:8000 with auto-reload enabled.
Server Options¶
--host: The host to bind to. Defaults to127.0.0.1.--port: The port to listen on. Defaults to8000.
Example:
Production Server (run)¶
The run command starts the server in production mode. This command is optimized for performance and does not include auto-reloading.
You can use the --host and --port options to configure the server, just like with the dev command. It's recommended to configure the number of workers in your config.toml file for production use.
Route Management¶
The routes command provides a set of tools for managing your application's routes.
routes list¶
Lists all the registered routes in your application. This is useful for debugging and for getting an overview of your application's endpoints.
routes add¶
Creates a new route file with a basic get function.
This will create the file routes/users/profile.py.
routes rm¶
Removes a route file.
This will delete the file routes/users/profile.py.
routes mv¶
Moves or renames a route file.
This will move the file routes/users/profile.py to routes/account/settings.py.
Database Migrations¶
Ushka provides a set of commands to help you manage your database schema using Alembic.
db init¶
This command initializes the migrations environment. It creates a migrations directory and an alembic.ini file in your project.
db make¶
Once you've made changes to your models (e.g., added a new column), you can use the make command to automatically generate a new migration script.
db migrate¶
This command applies all pending migrations to your database.
db revert¶
If you need to undo a migration, you can use the revert command. By default, it will revert the last migration.
db status¶
This command shows the current revision of your database.
db history¶
This command shows the full migration history.
Ushka Tip: Database migrations are a powerful tool for managing changes to your database schema over time. It's a good practice to create a new migration for every change you make to your models. This makes it easy to track changes and to collaborate with other developers.