Note: This package is currently in development. Expect frequent updates and potential breaking changes.
Tortoise Shell is inspired by the awesome Django-Extensions package, particularly the shell_plus feature. This tool is like shell_plus for Tortoise ORM, designed to simplify your workflow by automatically loading your models and database connection into an interactive IPython shell.
- Automatic Model Import: Just like Django-Extension's
shell_plus, Tortoise Shell automatically imports all your Tortoise ORM models into the IPython shell. - Easy Configuration: Set your models and database connection string in a simple TOML file, and you're ready to go.
-
Install Tortoise Shell:
pip install tortoise-shell
-
Ensure you have Tortoise-ORM and IPython installed:
pip install tortoise-orm ipython
-
Create a Configuration File:
Create a
config.tomlfile with the following content:[db] DB_URL = "your_app.config.POSTGRES_DB" # Enter the module path to your DB connection string [models] all_models = "your_app.config.all_models" # Enter the module path to your all_models list
DB_URL: The path to your database connection string.all_models: The path to your list of model modules.
-
Your Project's Configuration:
In your project’s
config.pyorsettings.py, define your Tortoise ORM setup:# config.py or settings.py POSTGRES_DB = "postgres://user:password@localhost:5432/mydatabase" all_models = [ "app1.models", "app2.models", ] TORTOISE_ORM = { 'connections': { 'default': POSTGRES_DB }, 'apps': { 'models': { 'models': all_models, 'default_connection': 'default', }, }, }
Once you've set up config.toml, simply run the IPython launcher script to start the shell with your models preloaded:
tortoise-shell