Skip to content

LeoTurnell-Ritson/tortoise-typer

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Tortoise Typer

Module to turn any Tortoise ORM model into a Typer CLI application.

Example Usage

Simply add a ModelTyper instance to your Typer application, passing the model class you want to manage. We let you choose how to initialise and close the Tortoise ORM connections, so you can integrate it into your existing application without any issues.

import asyncio

from tortoise import Tortoise
from typer import Typer
from tortoise_typer import ModelTyper

from myapp.models import MyModel 
from myapp.config import CONFIG

app = Typer()
app.add_typer(
    ModelTyper(MyModel),
    name="mymodel",  # default subcommand name
    help="Manage MyModel instances",
)

if __name__ == "__main__":
    asyncio.run(Tortoise.init(config=CONFIG))
    
    try:
        app()
    finally:
        asyncio.run(Tortoise.close_connections())

About

Build a CLI tool for any Tortoise ORM model with this lighweight package build on top of typer.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages