Skip to main content

A command line app for creating Backends with FastAPI

Project description

Kamaqi

A command line app for creating Backends with FastAPI, inspired in Artisan from Laravel and manage.py from Django.

The key features are:

  • Creates a normal project or a project with Docker.
  • Chooses a MySQL, PostgreSQL or SQLite database.
  • Works as with Django creating apps.
  • Every application created with Kamaqi contains a minimum CRUD.
  • Integration between SQLAlchemy and Alembic for migrations.

What is an app?

An application is a module of your project, which manages the logic of an actor of your application, for example (users, products, shops ... etc). Generally, an app is associated with a table in the database on which you want to do CRUD operations and they are named in the plural.

Every app created with Kamaqi contains the following files. For example:

users
├── crud.py
├── router.py
└── schemas.py
  • The schemas.py file contains classes of validation for input and output data using Pydantic. For example:
from pydantic import BaseModel,EmailStr

class UserCreate(BaseModel):
    name:str
    email:EmailStr
    password:str

class UserRead(BaseModel):
    id:int
    name:str
    email:EmailStr
  • The router.py contains an APIRouter and endpoint functions. for example:
from fastapi import APIRouter,Depends,status
from users.schemas import UserCreate
from users.schemas import UserRead
from users.crud import insert_user

from sqlalchemy.orm import Session
from database.database import get_db

users_routes= APIRouter(prefix="/api/v1/users")

@users_routes.post(path="/create/",
                 tags=["Users"],
                 response_model=UserRead,
                 status_code=status.HTTP_201_CREATED)
async def create_user(user_data:UserCreate,
                      db:Session=Depends(get_db)):

    return insert_user(db,user_data)
  • The crud.py contains a CRUD functions for your modules as insert_app, update_app, select_app ... etc. For example:
from users.schemas import UserCreate
from sqlalchemy.orm import Session
from database import models

def insert_user(db: Session, 
                user:UserCreate):

    db_user = models.User(**user.dict())
    db.add(db_user)
    db.commit()
    db.refresh(db_user)

    return db_app

This is just an example, in a real development environment, before inserting the user into the database should encrypt the password, check if the user is not registered...etc.

Project Structure

When creates a new project with Kamaqi this can have the following structures.

  • A projects with Docker following the next structure.
project_name
├── db_volume
├── docker-compose.yaml
├── Dockerfile
├── kamaqi.json
├── requirements.txt
└── src
    ├── alembic.ini
    ├── database
       ├── database.py
       ├── models.py
    ├── main.py
    ├── .env
    ├── migrations
       ├── env.py
       ├── script.py.mako
       └── versions
    ├── users
       ├── crud.py
       ├── router.py
       └── schemas.py
    └── project_name
        ├── auth.py
        ├── exceptions.py
        ├── router.py
        ├── schemas.py
        └── settings.py
  • The normal projects following the nex structure.
project_name
├── alembic.ini
├── database
│   ├── database.py
│   └── models.py
├── env
├── kamaqi.json
├── main.py
├── .env
├── migrations
│   ├── env.py
│   ├── script.py.mako
│   └── versions
├── requirements.txt
├── users
│   ├── crud.py
│   ├── router.py
│   └── schemas.py
└── project_name
    ├── auth.py
    ├── exceptions.py
    ├── router.py
    ├── schemas.py
    └── settings.py
  • In normal projects the env directory is the Python virtual environment.

  • The .env file contains the environment variables.

  • The project_name is the main app in to the project.

  • auth.py contains functions for hashing passwords, verify passwords and create access tokens.

  • exceptions.py contains some exceptions.

  • settings.py contains classes and functions that provide environment variables like secret keys, database connection parameters...etc. These variables are taken from the .env file.

Installation:

Install Kamaqi in the global environment.

pip install kamaqi

For help on Kamaqi commands and parameters, use.

kamaqi --help 
kamaqi command --help

Basic Usage:

Init your project:

kamaqi init project project_name

Choose the options, for setting your project. Remember for create projects with docker requires docker and docker-compose installed.

Run your project

cd project_name
kamaqi run project

Add apps to your project

Add an app

kamaqi add app users

Add multiple apps

kamaqi add apps users products sales ... etc

Create files for your apps

Kamaqi upgrade apps 
  • Refresh files in your editor.
  • Refresh the FastAPI documentation.

Review your project settings

kamaqi show config

Review your project apps

kamaqi show apps

Database migrations

For update your database tables.

kamaqi upgrade tables -m"A description about your changes"

To connect to MySQL or PostgreSQL database use.

  • For projects with Docker, review the docker-compose.yaml and use the database environment variables or use the following parameters.
DATABASE_USER = your_project_name_user
DATABASE_PASSWORD = your_project_name_password
DATABASE_NAME = your_project_name_db
DATABASE_PORT = MySQL 3306  and PostgreSQL 5432
  • For normal projects use your settings and in the .env and edit the connection parameters.

  • For SQLite databases use a editor extension or a other software.

Project Status

  • The project is currently under development and may contain errors.

  • You can contribute to this project, reporting bugs, writing documentation, writing tests, with pull requests... etc.

For more information, visit GitHub repository

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

kamaqi-0.1.9.tar.gz (18.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

kamaqi-0.1.9-py3-none-any.whl (23.5 kB view details)

Uploaded Python 3

File details

Details for the file kamaqi-0.1.9.tar.gz.

File metadata

  • Download URL: kamaqi-0.1.9.tar.gz
  • Upload date:
  • Size: 18.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.3.2 CPython/3.10.9 Linux/5.15.0-1031-azure

File hashes

Hashes for kamaqi-0.1.9.tar.gz
Algorithm Hash digest
SHA256 8e3b699572bb658438f8d268933970f3ed315cd509d1c655f5d52e5b059f3338
MD5 7148af83d48910c66cc109a72cd393aa
BLAKE2b-256 0084c77fdc990de2c8455c0b4d37aaff7b2bda436033ca49dd4184ab26ad108a

See more details on using hashes here.

File details

Details for the file kamaqi-0.1.9-py3-none-any.whl.

File metadata

  • Download URL: kamaqi-0.1.9-py3-none-any.whl
  • Upload date:
  • Size: 23.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.3.2 CPython/3.10.9 Linux/5.15.0-1031-azure

File hashes

Hashes for kamaqi-0.1.9-py3-none-any.whl
Algorithm Hash digest
SHA256 0bfa2619d0e09889ac39cd0ad484694133367d7a24d86497d9a7dea4ba478032
MD5 3d207abbfdfab02bfae4606fba32a770
BLAKE2b-256 e5be9df10214d98ca7d1e1545429d9d3fea01bddfb3d91ebda906bb45e9f0545

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page