Metadata-Version: 2.1
Name: fastapi-gene
Version: 0.0.7
Summary: Create and Run migration for fastapi project
Author-Email: bhuwan pandey <bhuwanpandey@gmail.com>
License: MIT
Classifier: Intended Audience :: Information Technology
Classifier: Intended Audience :: System Administrators
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python
Classifier: Topic :: Software Development :: Libraries :: Application Frameworks
Classifier: Topic :: Software Development :: Libraries :: Python Modules
Classifier: Topic :: Software Development :: Libraries
Classifier: Topic :: Software Development
Classifier: Typing :: Typed
Classifier: Development Status :: 4 - Beta
Classifier: Framework :: FastAPI
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: MIT License
Classifier: Programming Language :: Python :: 3 :: Only
Classifier: Programming Language :: Python :: 3.8
Classifier: Programming Language :: Python :: 3.9
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Requires-Python: >=3.8
Requires-Dist: typer>=0.12.3
Requires-Dist: uvicorn[standard]>=0.15.0
Requires-Dist: rich-toolkit>=0.11.1
Requires-Dist: jinja2>=3.1.6
Requires-Dist: httpx>=0.28.1
Requires-Dist: alembic>=1.14.1
Description-Content-Type: text/markdown

# FastAPI-GENE


A lightweight CLI tool to scaffold fastapi projects, run migrations and migrate migration files.

## Installation

Create and activate a virtual environment and then install **fastapi_gene**:


```console
$ pip install fastapi_gene

```

## Usage

Here are some examples of what **fastapi_gene** can do:

### `fastapi_gene createproject main`

It creates a fastapi project named `main` along with it's subfolder `models`,`schema`,`api` and file `app.py` inside it.

<div class="termy">

```console

main/
├── app.py
└── main/
    ├── __init__.py
    ├── api/
    │   ├── __init__.py
    │   └── item.py
    ├── models/
    │   └── __init__.py
    └── schema/
        ├── __init__.py
        └── item.py

```
</div>

To run the project just change path to `main` and run `fastapi dev`.now, you can navigate to <a href="http://127.0.0.1:8000/docs/" target="_blank">http://127.0.0.1:8000/docs/</a> to see autogenerated `items` endpoints but make sure to install `fastapi` on your enviroment.😊

### `fastapi_gene createuser fastapi-users[sqlalchemy]`

It creates file and add user table on it as well as map endpoint into your project automatically from `fastapi-users[sqlalchemy]` module but project structure should be maintained to work as smoothly.
- Supported modules are:
  - `fastapi-users[sqlalchemy]`
  - `fastapi-users[sqlalchemy,oauth]`
  - `fastapi-users[beanie]`
  - `fastapi-users[beanie,oauth]`

Now, File structure changed to

<div class="termy">

```console

main/
├── app.py
└── main/
    ├── __init__.py
    ├── api/
    │   ├── __init__.py
    │   |── item.py
    |   └── users.py    #created
    |
    ├── models/
    │   |── __init__.py
    |   |── db.py       #created
    |   └── users.py    #created
    |
    └── schema/
        ├── __init__.py
        |── item.py
        └── users.py    #created

// To reflect users endpoint on project include `user_router` in `app.py` as
# app.py

from fastapi import FastAPI
from main.api import item_router,user_router

app = FastAPI()


app.include_router(item_router)
app.include_router(user_router)

```
</div>


### `fastapi_gene makemigrations`
#### `fastapi_gene makemigrations init`
Migrations directory wasnot created to store migrations file. To create that, you should run above command in your terminal and it creates migrations directory named `alembic`. It works same as `alembic init alembic` but you can also provide custom name as `fastapi_gene makemigrations init --name=migrations`

<div class="termy">

```console

main/
├── app.py
├── alembic/...  #created
├── alembic.ini  #created
└── main/...

```
</div>

#### `fastapi_gene makemigrations -m "create user tables" `
After importing `Base` from user model and `sqlalchemy_url` inside env.py of migrations directory, you can run this command which will create the migration file with named `randomnumber_create_user_tables.py` inside version directory of migrations. It works same as `alembic revision --autogenerate -m "create user tables"`.


### `fastapi_gene migrate up`

It applies all migrations upto latest version. It works same as `alembic upgrade head`. By default, it passes `head` revision but you can provide desire revision as `fastapi_gene migrate up revision_id`

### `fastapi_gene migrate down`

It reverts all migrations, bringing the database back to its initial empty state. It works same as `alembic downgrade base`. By default, it passes `base` revision but you can provide desire revision as `fastapi_gene migrate down revision_id`


## Notes
* `command`: To know about all the commands `fastapi_gene --help`
* `specific-command`: For the information of specific commands `fastapi_gene "command_name" --help`
