{"id":13465617,"url":"https://github.com/rochacbruno/fastapi-project-template","last_synced_at":"2025-04-05T20:06:11.264Z","repository":{"id":37800758,"uuid":"406031823","full_name":"rochacbruno/fastapi-project-template","owner":"rochacbruno","description":"DO NOT FORK, CLICK \"Use this template\" - The base to start an openapi project featuring: SQLModel, Typer, FastAPI, JWT Token Auth, Interactive Shell, Management Commands.","archived":false,"fork":false,"pushed_at":"2022-12-19T23:22:38.000Z","size":266,"stargazers_count":411,"open_issues_count":10,"forks_count":37,"subscribers_count":7,"default_branch":"main","last_synced_at":"2025-04-02T13:52:14.615Z","etag":null,"topics":["api-template","fastapi","hacktoberfest","project-template","python-project-template","python-template","rochacbruno-template","template"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"unlicense","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/rochacbruno.png","metadata":{"files":{"readme":"README.md","changelog":"HISTORY.md","contributing":"CONTRIBUTING.md","funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null},"funding":{"github":["rochacbruno"],"patreon":null,"open_collective":null,"ko_fi":null,"tidelift":null,"community_bridge":null,"liberapay":null,"issuehunt":null,"otechie":null,"custom":null}},"created_at":"2021-09-13T15:39:49.000Z","updated_at":"2025-03-29T20:17:20.000Z","dependencies_parsed_at":"2023-01-29T23:15:52.832Z","dependency_job_id":null,"html_url":"https://github.com/rochacbruno/fastapi-project-template","commit_stats":null,"previous_names":[],"tags_count":0,"template":true,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rochacbruno%2Ffastapi-project-template","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rochacbruno%2Ffastapi-project-template/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rochacbruno%2Ffastapi-project-template/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rochacbruno%2Ffastapi-project-template/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/rochacbruno","download_url":"https://codeload.github.com/rochacbruno/fastapi-project-template/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247393568,"owners_count":20931812,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["api-template","fastapi","hacktoberfest","project-template","python-project-template","python-template","rochacbruno-template","template"],"created_at":"2024-07-31T15:00:32.668Z","updated_at":"2025-04-05T20:06:11.235Z","avatar_url":"https://github.com/rochacbruno.png","language":"Python","funding_links":["https://github.com/sponsors/rochacbruno","https://github.com/sponsors/rochacbruno/"],"categories":["Python"],"sub_categories":[],"readme":"# FastAPI Project Template\n\nThe base to start an openapi project featuring: SQLModel, Typer, FastAPI, JWT Token Auth, Interactive Shell, Management Commands. \n\nSee also\n\n-  [Python-Project-Template](https://github.com/rochacbruno/python-project-template/) for a lean, low dependency Python app.\n-  [Flask-Project-Template](https://github.com/rochacbruno/flask-project-template/) for a full feature Flask project including database, API, admin interface, etc.\n\n\n### HOW TO USE THIS TEMPLATE\n\n\u003e **DO NOT FORK** this is meant to be used from **[Use this template](https://github.com/rochacbruno/fastapi-project-template/generate)** feature.\n\n1. Click on **[Use this template](https://github.com/rochacbruno/fastapi-project-template/generate)**\n3. Give a name to your project  \n   (e.g. `my_awesome_project` recommendation is to use all lowercase and underscores separation for repo names.)\n3. Wait until the first run of CI finishes  \n   (Github Actions will process the template and commit to your new repo)\n4. If you want [codecov](https://about.codecov.io/sign-up/) Reports and Automatic Release to [PyPI](https://pypi.org)  \n  On the new repository `settings-\u003esecrets` add your `PIPY_API_TOKEN` and `CODECOV_TOKEN` (get the tokens on respective websites)\n4. Read the file [CONTRIBUTING.md](CONTRIBUTING.md)\n5. Then clone your new project and happy coding!\n\n\u003e **NOTE**: **WAIT** until first CI run on github actions before cloning your new project.\n\n### What is included on this template?\n\n- 🖼️ The base to start an openapi project featuring: SQLModel, Typer, FastAPI, VueJS.\n- 📦 A basic [setup.py](setup.py) file to provide installation, packaging and distribution for your project.  \n  Template uses setuptools because it's the de-facto standard for Python packages, you can run `make switch-to-poetry` later if you want.\n- 🤖 A [Makefile](Makefile) with the most useful commands to install, test, lint, format and release your project.\n- 📃 Documentation structure using [mkdocs](http://www.mkdocs.org)\n- 💬 Auto generation of change log using **gitchangelog** to keep a HISTORY.md file automatically based on your commit history on every release.\n- 🐋 A simple [Containerfile](Containerfile) to build a container image for your project.  \n  `Containerfile` is a more open standard for building container images than Dockerfile, you can use buildah or docker with this file.\n- 🧪 Testing structure using [pytest](https://docs.pytest.org/en/latest/)\n- ✅ Code linting using [flake8](https://flake8.pycqa.org/en/latest/)\n- 📊 Code coverage reports using [codecov](https://about.codecov.io/sign-up/)\n- 🛳️ Automatic release to [PyPI](https://pypi.org) using [twine](https://twine.readthedocs.io/en/latest/) and github actions.\n- 🎯 Entry points to execute your program using `python -m \u003cproject_name\u003e` or `$ project_name` with basic CLI argument parsing.\n- 🔄 Continuous integration using [Github Actions](.github/workflows/) with jobs to lint, test and release your project on Linux, Mac and Windows environments.\n\n\u003e Curious about architectural decisions on this template? read [ABOUT_THIS_TEMPLATE.md](ABOUT_THIS_TEMPLATE.md)  \n\u003e If you want to contribute to this template please open an [issue](https://github.com/rochacbruno/fastapi-project-template/issues) or fork and send a PULL REQUEST.\n\n[❤️ Sponsor this project](https://github.com/sponsors/rochacbruno/)\n\n\u003c!--  DELETE THE LINES ABOVE THIS AND WRITE YOUR PROJECT README BELOW --\u003e\n\n---\n# project_name\n\n[![codecov](https://codecov.io/gh/author_name/project_urlname/branch/main/graph/badge.svg?token=project_urlname_token_here)](https://codecov.io/gh/author_name/project_urlname)\n[![CI](https://github.com/author_name/project_urlname/actions/workflows/main.yml/badge.svg)](https://github.com/author_name/project_urlname/actions/workflows/main.yml)\n\nproject_description\n\n## Install\n\nfrom source\n```bash\ngit clone https://github.com/author_name/project_urlname project_name\ncd project_name\nmake install\n```\n\nfrom pypi\n\n```bash\npip install project_name\n```\n\n## Executing\n\n```bash\n$ project_name run --port 8080\n```\n\nor\n\n```bash\npython -m project_name run --port 8080\n```\n\nor\n\n```bash\n$ uvicorn project_name:app\n```\n\n## CLI\n\n```bash\n❯ project_name --help\nUsage: project_name [OPTIONS] COMMAND [ARGS]...\n\nOptions:\n  --install-completion [bash|zsh|fish|powershell|pwsh]\n                                  Install completion for the specified shell.\n  --show-completion [bash|zsh|fish|powershell|pwsh]\n                                  Show completion for the specified shell, to\n                                  copy it or customize the installation.\n  --help                          Show this message and exit.\n\nCommands:\n  create-user  Create user\n  run          Run the API server.\n  shell        Opens an interactive shell with objects auto imported\n```\n\n### Creating a user\n\n```bash\n❯ project_name create-user --help\nUsage: project_name create-user [OPTIONS] USERNAME PASSWORD\n\n  Create user\n\nArguments:\n  USERNAME  [required]\n  PASSWORD  [required]\n\nOptions:\n  --superuser / --no-superuser  [default: no-superuser]\n  --help \n```\n\n**IMPORTANT** To create an admin user on the first run:\n\n```bash\nproject_name create-user admin admin --superuser\n```\n\n### The Shell\n\nYou can enter an interactive shell with all the objects imported.\n\n```bash\n❯ project_name shell       \nAuto imports: ['app', 'settings', 'User', 'engine', 'cli', 'create_user', 'select', 'session', 'Content']\n\nIn [1]: session.query(Content).all()\nOut[1]: [Content(text='string', title='string', created_time='2021-09-14T19:25:00.050441', user_id=1, slug='string', id=1, published=False, tags='string')]\n\nIn [2]: user = session.get(User, 1)\n\nIn [3]: user.contents\nOut[3]: [Content(text='string', title='string', created_time='2021-09-14T19:25:00.050441', user_id=1, slug='string', id=1, published=False, tags='string')]\n```\n\n## API\n\nRun with `project_name run` and access http://127.0.0.1:8000/docs\n\n![](https://raw.githubusercontent.com/rochacbruno/fastapi-project-template/master/docs/api.png)\n\n\n**For some api calls you must authenticate** using the user created with `project_name create-user`.\n\n## Testing\n\n``` bash\n❯ make test\nBlack All done! ✨ 🍰 ✨\n13 files would be left unchanged.\nIsort All done! ✨ 🍰 ✨\n6 files would be left unchanged.\nSuccess: no issues found in 13 source files\n================================ test session starts ===========================\nplatform linux -- Python 3.9.6, pytest-6.2.5, py-1.10.0, pluggy-1.0.0 -- \n/fastapi-project-template/.venv/bin/python3\ncachedir: .pytest_cache\nrootdir: /fastapi-project-template\nplugins: cov-2.12.1\ncollected 10 items                                                                                                                               \n\ntests/test_app.py::test_using_testing_db PASSED                           [ 10%]\ntests/test_app.py::test_index PASSED                                      [ 20%]\ntests/test_cli.py::test_help PASSED                                       [ 30%]\ntests/test_cli.py::test_cmds_help[run-args0---port] PASSED                [ 40%]\ntests/test_cli.py::test_cmds_help[create-user-args1-create-user] PASSED   [ 50%]\ntests/test_cli.py::test_cmds[create-user-args0-created admin2 user] PASSED[ 60%]\ntests/test_content_api.py::test_content_create PASSED                     [ 70%]\ntests/test_content_api.py::test_content_list PASSED                       [ 80%]\ntests/test_user_api.py::test_user_list PASSED                             [ 90%]\ntests/test_user_api.py::test_user_create PASSED                           [100%]\n\n----------- coverage: platform linux, python 3.9.6-final-0 -----------\nName                              Stmts   Miss  Cover\n-----------------------------------------------------\nproject_name/__init__.py              4      0   100%\nproject_name/app.py                  16      1    94%\nproject_name/cli.py                  21      0   100%\nproject_name/config.py                5      0   100%\nproject_name/db.py                   10      0   100%\nproject_name/models/__init__.py       0      0   100%\nproject_name/models/content.py       47      1    98%\nproject_name/routes/__init__.py      11      0   100%\nproject_name/routes/content.py       52     25    52%\nproject_name/routes/security.py      15      1    93%\nproject_name/routes/user.py          52     26    50%\nproject_name/security.py            103     12    88%\n-----------------------------------------------------\nTOTAL                               336     66    80%\n\n\n========================== 10 passed in 2.34s ==================================\n\n```\n\n## Linting and Formatting\n\n```bash\nmake lint  # checks for linting errors\nmake fmt   # formats the code\n```\n\n\n## Configuration\n\nThis project uses [Dynaconf](https://dynaconf.com) to manage configuration.\n\n```py\nfrom project_name.config import settings\n```\n\n## Acessing variables\n\n```py\nsettings.get(\"SECRET_KEY\", default=\"sdnfjbnfsdf\")\nsettings[\"SECRET_KEY\"]\nsettings.SECRET_KEY\nsettings.db.uri\nsettings[\"db\"][\"uri\"]\nsettings[\"db.uri\"]\nsettings.DB__uri\n```\n\n## Defining variables\n\n### On files\n\nsettings.toml\n\n```toml\n[development]\ndynaconf_merge = true\n\n[development.db]\necho = true\n```\n\n\u003e `dynaconf_merge` is a boolean that tells if the settings should be merged with the default settings defined in project_name/default.toml.\n\n### As environment variables\n```bash\nexport PROJECT_NAME_KEY=value\nexport PROJECT_NAME_KEY=\"@int 42\"\nexport PROJECT_NAME_KEY=\"@jinja {{ this.db.uri }}\"\nexport PROJECT_NAME_DB__uri=\"@jinja {{ this.db.uri | replace('db', 'data') }}\"\n```\n\n### Secrets\n\nThere is a file `.secrets.toml` where your sensitive variables are stored,\nthat file must be ignored by git. (add that to .gitignore)\n\nOr store your secrets in environment variables or a vault service, Dynaconf\ncan read those variables.\n\n### Switching environments\n\n```bash\nPROJECT_NAME_ENV=production project_name run\n```\n\nRead more on https://dynaconf.com\n\n## Development\n\nRead the [CONTRIBUTING.md](CONTRIBUTING.md) file.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frochacbruno%2Ffastapi-project-template","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frochacbruno%2Ffastapi-project-template","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frochacbruno%2Ffastapi-project-template/lists"}