Package: kamaqi
KamaqiA command line app for creating Backends withFastAPI, inspired inArtisanfromLaravelandmanage.pyfromDjango.ContentThe key features areInstallationBasic usageProject StatusThe key features are:Creates a normal project or a project withDockeranddocker-compose.Chooses aMySQL,PostgreSQLorSQLitedatabase.Works as withDjangocreating  apps.Every application created withKamaqicontains a minimumCRUD.Integration betweenSQLAlchemyandAlembicfor 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.pyTheschemas.pyfile contains classes of validation for input and output  data using
Pydantic. For example:frompydanticimportBaseModel,EmailStrclassUserCreate(BaseModel):name:stremail:EmailStrpassword:strclassUserRead(BaseModel):id:intname:stremail:EmailStrTherouter.pycontains an APIRouter and endpoint functions. for example:fromfastapiimportAPIRouter,Depends,statusfromusers.schemasimportUserCreatefromusers.schemasimportUserReadfromusers.crudimportinsert_userfromsqlalchemy.ormimportSessionfromdatabase.databaseimportget_dbusers_routes=APIRouter(prefix="/api/v1/users")@users_routes.post(path="/create/",tags=["Users"],response_model=UserRead,status_code=status.HTTP_201_CREATED)asyncdefcreate_user(user_data:UserCreate,db:Session=Depends(get_db)):returninsert_user(db,user_data)Thecrud.pycontains a CRUD functions for your modules as insert_app, update_app, select_app ... etc. For example:fromusers.schemasimportUserCreatefromsqlalchemy.ormimportSessionfromdatabaseimportmodelsdefinsert_user(db:Session,user:UserCreate):db_user=models.User(**user.dict())db.add(db_user)db.commit()db.refresh(db_user)returndb_appThis 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 StructureWhen working on a project with Kamaqi, it can have the following structures.It is very important to follow those structures to create applications, perform migrations, run your project and use allKamaqicommands.Otherwise you could build the applications in an unwanted directory, not find the models.py file to add the models to, and also the migrations could fail.Let's remember thatFastAPIis a microframework and therefore doesn't give you a project structure likeDjangowould. That is why we are free to structure our project as we want.Kamaqiis a tool that will help you streamline your development processes, but in return you must respect its structure. For this reason we chose a structure similar to that ofDjangosince this is a very mature framework and its way of working is one of the best.If you have suggestions for a better project structure or would like to contribute to the development of Kamaqi by adding new features, you can visitKamaqi GitHub.The projects withDockerfollowing 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.pyThe 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.pyIn the projects with dockerdb_volume/is the directory where is saved your database data.TheKamaqi.jsonfile contains the metadata of your project, this file is very important becauseKamaqiuses it to execute some commands.In normal projects theenv/directory is thePythonvirtual environment.The.envfile contains the environment
variables.Themigrations/directory contains the settings for make migrations withAlembic.Theproject_name/is the main app in to the project.project_name/auth.pycontains functions for hashing passwords, verify passwords and create access tokens.project_name/exceptions.pycontains some exceptions.project_name/settings.pycontains classes and functions that provide environment variables like secret keys, database connection parameters...etc. These variables are taken from the .env file.database/database.pycontains code for connecting to the database.database/models.pycontains your database models created withSQLALchemy, when your creates a newappkamaqi create a new basica model in themodels.pyfile.InstallationPrevious requirementsPython 3.10or higher.Kamaqiis now developed and tested in Ubuntu and other Linux distributions.If you useWindowsis recommended has installedWSL.Note: You can contribute to the development ofKamaqiby testing its operation inWindowsand reporting possible errors to improve the tool.Install Kamaqi in the global environment.pip3installkamaqiAnother way to install Kamaqi is usingpipxpipxinstallkamaqiBasic UsageFor help on Kamaqi commands and parameters, use.kamaqi--helpkamaqicommand--helpStart your projectStart project in a new directorykamaqistartprojectproject_nameStart project in the current directorykamaqistartproject.Choose the options, for setting your project.If you choose a normal project and you don't haveMySQLorPostgreSQLinstalled. it is recommended to selectSQLitedatabase.Remember for create projects with docker requiresdockeranddocker-composeinstalled.Run your projectcdproject_nameExecute the following commandskamaqirunprojectorkamaqirunproject--buildIf you works with docker the--buildoption makes a new image of your project before running.This is useful if you added a python library to your project when your container was running and you don't want the library to be lost on the next run, because the library is not found in the image.For more information reviewadd a Python libraryto your project.Explore the FastAPI documentation.For Kamaqi the default port is the 8000.Open in your browserhttp://localhost:8000/docsAdd apps to your projectAdd an appkamaqiaddappusersAdd multiple appskamaqiaddappsusersproductssales...etcCreate files for your appsKamaqiupgradeappsRefresh files in your editor.Refresh the FastAPI documentation.Review the themain.pyfile.Review your project settingskamaqishowconfigReview your project appskamaqishowappsDatabase migrationsFor update your database tables.kamaqimigratetables-m"A small description about your changes in database/models.py"Connecting to databaseFor projects with Docker, review thedocker-compose.yamland use the database environment variables
or use the following parameters.DATABASE_HOST=localhostorproject_name_dbDATABASE_USER=project_name_userDATABASE_PASSWORD=project_name_passwordDATABASE_NAME=project_name_dbDATABASE_PORT=MySQL3306andPostgreSQL5432For 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.Adding a Python library to your projectkamaqiadddeppython_library_nameorkamaqiadddepspython_library_name1python_library_name2In normal projects this comand add thepython_library_nameto the virtual environment(env)
and updates the requirements.txt file.In proyects with docker this command  add thepython_library_nameto the project container and
updates the requirements.txt file.
Then when you use the--buildthe new image of your project will be build with the new libraries.Removing a Python library to your projectkamaqiremovedeppython_library_nameorkamaqiremovedepspython_library_name1python_library_name2In normal projects this comand removes thepython_library_namein the virtual environment(env)
and updates the requirements.txt file.In proyects with docker this command  removes thepython_library_namein the project container and
updates the requirements.txt file.
Then when you use the--buildthe new image of your project will be build with the new libraries.Executing a command in your project containerkamaqiexec"any Linux command"Kamaqiuse theUbuntu:latestversion to build your project image. For this reason you can execute any command ofUbuntu.Remember that any change in the container at runtime will not be reflected in the project image.This method is not recommended for adding python libraries to the container as it will not update the requirements.txt fileProject StatusThe 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, visitGitHub repository