• Stars
    star
    290
  • Rank 138,500 (Top 3 %)
  • Language
    Python
  • License
    The Unlicense
  • Created over 2 years ago
  • Updated 12 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

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.

FastAPI Project Template

The base to start an openapi project featuring: SQLModel, Typer, FastAPI, JWT Token Auth, Interactive Shell, Management Commands.

See also

HOW TO USE THIS TEMPLATE

DO NOT FORK this is meant to be used from Use this template feature.

  1. Click on Use this template
  2. Give a name to your project
    (e.g. my_awesome_project recommendation is to use all lowercase and underscores separation for repo names.)
  3. Wait until the first run of CI finishes
    (Github Actions will process the template and commit to your new repo)
  4. If you want codecov Reports and Automatic Release to PyPI
    On the new repository settings->secrets add your PIPY_API_TOKEN and CODECOV_TOKEN (get the tokens on respective websites)
  5. Read the file CONTRIBUTING.md
  6. Then clone your new project and happy coding!

NOTE: WAIT until first CI run on github actions before cloning your new project.

What is included on this template?

  • πŸ–ΌοΈ The base to start an openapi project featuring: SQLModel, Typer, FastAPI, VueJS.
  • πŸ“¦ A basic setup.py file to provide installation, packaging and distribution for your project.
    Template uses setuptools because it's the de-facto standard for Python packages, you can run make switch-to-poetry later if you want.
  • πŸ€– A Makefile with the most useful commands to install, test, lint, format and release your project.
  • πŸ“ƒ Documentation structure using mkdocs
  • πŸ’¬ Auto generation of change log using gitchangelog to keep a HISTORY.md file automatically based on your commit history on every release.
  • πŸ‹ A simple Containerfile to build a container image for your project.
    Containerfile is a more open standard for building container images than Dockerfile, you can use buildah or docker with this file.
  • πŸ§ͺ Testing structure using pytest
  • βœ… Code linting using flake8
  • πŸ“Š Code coverage reports using codecov
  • πŸ›³οΈ Automatic release to PyPI using twine and github actions.
  • 🎯 Entry points to execute your program using python -m <project_name> or $ project_name with basic CLI argument parsing.
  • πŸ”„ Continuous integration using Github Actions with jobs to lint, test and release your project on Linux, Mac and Windows environments.

Curious about architectural decisions on this template? read ABOUT_THIS_TEMPLATE.md
If you want to contribute to this template please open an issue or fork and send a PULL REQUEST.

❀️ Sponsor this project


project_name

codecov CI

project_description

Install

from source

git clone https://github.com/author_name/project_urlname project_name
cd project_name
make install

from pypi

pip install project_name

Executing

$ project_name run --port 8080

or

python -m project_name run --port 8080

or

$ uvicorn project_name:app

CLI

❯ project_name --help
Usage: project_name [OPTIONS] COMMAND [ARGS]...

Options:
  --install-completion [bash|zsh|fish|powershell|pwsh]
                                  Install completion for the specified shell.
  --show-completion [bash|zsh|fish|powershell|pwsh]
                                  Show completion for the specified shell, to
                                  copy it or customize the installation.
  --help                          Show this message and exit.

Commands:
  create-user  Create user
  run          Run the API server.
  shell        Opens an interactive shell with objects auto imported

Creating a user

❯ project_name create-user --help
Usage: project_name create-user [OPTIONS] USERNAME PASSWORD

  Create user

Arguments:
  USERNAME  [required]
  PASSWORD  [required]

Options:
  --superuser / --no-superuser  [default: no-superuser]
  --help 

IMPORTANT To create an admin user on the first run:

project_name create-user admin admin --superuser

The Shell

You can enter an interactive shell with all the objects imported.

❯ project_name shell       
Auto imports: ['app', 'settings', 'User', 'engine', 'cli', 'create_user', 'select', 'session', 'Content']

In [1]: session.query(Content).all()
Out[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')]

In [2]: user = session.get(User, 1)

In [3]: user.contents
Out[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')]

API

Run with project_name run and access http://127.0.0.1:8000/docs

For some api calls you must authenticate using the user created with project_name create-user.

Testing

❯ make test
Black All done! ✨ 🍰 ✨
13 files would be left unchanged.
Isort All done! ✨ 🍰 ✨
6 files would be left unchanged.
Success: no issues found in 13 source files
================================ test session starts ===========================
platform linux -- Python 3.9.6, pytest-6.2.5, py-1.10.0, pluggy-1.0.0 -- 
/fastapi-project-template/.venv/bin/python3
cachedir: .pytest_cache
rootdir: /fastapi-project-template
plugins: cov-2.12.1
collected 10 items                                                                                                                               

tests/test_app.py::test_using_testing_db PASSED                           [ 10%]
tests/test_app.py::test_index PASSED                                      [ 20%]
tests/test_cli.py::test_help PASSED                                       [ 30%]
tests/test_cli.py::test_cmds_help[run-args0---port] PASSED                [ 40%]
tests/test_cli.py::test_cmds_help[create-user-args1-create-user] PASSED   [ 50%]
tests/test_cli.py::test_cmds[create-user-args0-created admin2 user] PASSED[ 60%]
tests/test_content_api.py::test_content_create PASSED                     [ 70%]
tests/test_content_api.py::test_content_list PASSED                       [ 80%]
tests/test_user_api.py::test_user_list PASSED                             [ 90%]
tests/test_user_api.py::test_user_create PASSED                           [100%]

----------- coverage: platform linux, python 3.9.6-final-0 -----------
Name                              Stmts   Miss  Cover
-----------------------------------------------------
project_name/__init__.py              4      0   100%
project_name/app.py                  16      1    94%
project_name/cli.py                  21      0   100%
project_name/config.py                5      0   100%
project_name/db.py                   10      0   100%
project_name/models/__init__.py       0      0   100%
project_name/models/content.py       47      1    98%
project_name/routes/__init__.py      11      0   100%
project_name/routes/content.py       52     25    52%
project_name/routes/security.py      15      1    93%
project_name/routes/user.py          52     26    50%
project_name/security.py            103     12    88%
-----------------------------------------------------
TOTAL                               336     66    80%


========================== 10 passed in 2.34s ==================================

Linting and Formatting

make lint  # checks for linting errors
make fmt   # formats the code

Configuration

This project uses Dynaconf to manage configuration.

from project_name.config import settings

Acessing variables

settings.get("SECRET_KEY", default="sdnfjbnfsdf")
settings["SECRET_KEY"]
settings.SECRET_KEY
settings.db.uri
settings["db"]["uri"]
settings["db.uri"]
settings.DB__uri

Defining variables

On files

settings.toml

[development]
dynaconf_merge = true

[development.db]
echo = true

dynaconf_merge is a boolean that tells if the settings should be merged with the default settings defined in project_name/default.toml.

As environment variables

export PROJECT_NAME_KEY=value
export PROJECT_NAME_KEY="@int 42"
export PROJECT_NAME_KEY="@jinja {{ this.db.uri }}"
export PROJECT_NAME_DB__uri="@jinja {{ this.db.uri | replace('db', 'data') }}"

Secrets

There is a file .secrets.toml where your sensitive variables are stored, that file must be ignored by git. (add that to .gitignore)

Or store your secrets in environment variables or a vault service, Dynaconf can read those variables.

Switching environments

PROJECT_NAME_ENV=production project_name run

Read more on https://dynaconf.com

Development

Read the CONTRIBUTING.md file.

More Repositories

1

py2rs

A quick reference guide for the Pythonista in the process of becoming a Rustacean
CSS
2,022
star
2

python-week-2022

Template Para a Python Week 2002 - 25 a 29 de Abril na LINUXTips
Python
1,848
star
3

rust-python-example

Example of using Rust to Extend Python
Python
776
star
4

python-project-template

DO NOT FORK, CLICK ON "Use this template" - A github template to start a Python Project - this uses github actions to generate your project based on the template.
Makefile
753
star
5

nameko-example

Code for example in this post: http://brunorocha.org/python/microservices-with-python-rabbitmq-and-nameko.html
Python
191
star
6

flask-powered

List of companies using Flask framework - who is using Flask?
134
star
7

python-base

https://www.linuxtips.io/products/python-base
Python
129
star
8

flask-project-template

DO NOT FORK, CLICK "Use this template" - A github template to start a Flask Project - this uses github actions to generate your project based on the template.
Python
121
star
9

rust_memes

The best memes and stickers about #rust #rustlang - listed here for easy use on talks and share
Rust
106
star
10

learndynaconf

Learn Dynaconf - the best config library for Python :)
Python
61
star
11

talkshow

A Call 4 Papers System - A simple base app as example of Flask Architecture
Python
59
star
12

wtf

What The Flask - News App da parte 1 do artigo What the Flask
Python
50
star
13

vegan_recipes

100% vegan recipes
48
star
14

dotfiles

My Environment Configurations
Lua
42
star
15

fastapi-workshop

Material do workshop - Criando API com FastAPI da LINUXtips
Python
36
star
16

python-hello-world

Hello World
28
star
17

rochacbruno

My Profile
20
star
18

i_am_learning_rust

My Rust exercices with notes (mostly based on Rust Essentials and TRPL books + exercism)
Rust
20
star
19

dundie-api

Projeto do Treinamento Python Web API LINUXtips
Shell
18
star
20

dundie-rewards

point rewards system for dunder mifflin company
Python
17
star
21

makectl

WIP - Generate and Manage targets in your makefiles.
Rust
16
star
22

python-web-api

https://cursodepython.com.br
15
star
23

DURC

Declarative Understandable Reproducible Cases - Powered by Ansible
Python
11
star
24

aprenda-rust

https://bit.ly/aprendarust
Rust
10
star
25

thunar-actions

My actions used in Thunar (XFCE file manager)
Shell
9
star
26

dynaconf_ng

You know... when a repo is created having `_ng` suffix it means the main project will evolve or is going to die...
Python
6
star
27

Postgre

A Database System Inspired by Postgres
6
star
28

rust-dynaconf

GO TO https://github.com/rubik/hydroconf
Rust
5
star
29

discord_classroom

Discord bot to work as a Learning Management System - LMS
Rust
5
star
30

python-base-1

Codigos do Treinamento Python Expert Modulo Base
Python
4
star
31

bruno-api-done

Python
4
star
32

exercism

My exercism solutions, don't COPY it!!! :) try yourself at -> https://exercism.io/
Rust
3
star
33

fastapi-workshop-template

⬅️ Click on Use This Template - Template para o workshop de FastAPI da Codecon 2021
Python
3
star
34

rust-intro

Rust Intro Repository for Data Umbrella Workshop - This repository is almost empty, only some instructions on the readme.
3
star
35

web-api-example

Python
2
star
36

micro-rust-plugin

Micro Editor rust plugin
Lua
2
star
37

trivia

Python TUI for Open Trivia Database
Python
2
star
38

smarter

Some objects could be smarter
Python
2
star
39

ansible-test

ansible.test.case is a testing framework and test runner within ansible tasks, it talks to API using openapispec, to Selenium using pageObjects and CLI using pexpect.
HTML
2
star
40

flask_admin_example

FlaskConf 2018 talk code
Python
1
star
41

dataclass-validator

Python
1
star
42

wagd

Workspace for Ansible Galaxy Development
1
star
43

conffee-maker

`$cm` or Confee Maker is a command terminal interface TUI to generate configuration files for different applications based on templates.
Rust
1
star