Skip to main content

FastAPI but with JWT authentication built for you, server-side task scheduling and more. :)

Project description

FasterAPI

This is a simple start point for backend application based on FastAPI with JWT user authentication built for you. :)

How to use

First install it with pip. You do not need to install FastAPI seperately. All related libaray has been added as dependencies.

pip install FasterAPI

Then, you have to create a "auth-config.yaml" file, please make sure the file name is excat the same. This file should contains:

SQLALCHEMY_DATABASE_URL: "postgresql://postgres:postgres@127.0.0.1:5432/postgres" # url to your postgresql
SECRET_KEY: "8cfba7f89fca29a5f86cd8e02cb5381070690e378fc26cce4a311f84ce93672a" # create with openssl rand -hex 32
ALGORITHM: "HS256" # encryption algorithm
TOKEN_URL: "login" # url for login
TOKEN_EXPIRATION_TIME: 1 # token expiration time in minutes.
ALLOW_SELF_REGISTRATION: True # if true, anyone could register a user account. Otherwise, only superuser could.
ALLOW_MULTI_SESSIONS: False # if true, same user can login from different client. Otherwise, only one client is allowed.
# if any following configuration is missing, lowest security config will used for faster development!
# for non-website (include web app) you may want to use the default settings so your request won't be blocked.
ALLOW_CREDENTIALS: False # Here goes your choice for whether allow credential for CSRF protection
ALLOWED_ORIGINS: # Here goes your allowed origns for CSRF protection
  - "*"
ALLOWED_METHODS: # Here goes your allowed method for CSRF protection
  - "*"
ALLOWED_HEADERS: # Here goes your allowed headers for CSRF protection
  - "*"

Now, create a "main.py" file:

import uvicorn
from FasterAPI.utils import init_migration, create_superuser

if __name__ == "__main__":
    # create a superuser, optional
    create_superuser(
        username="admin",
        password="admin",
        first_name="admin",
        last_name="admin",
        email="admin@admin.com"
    )
    # start the fastapi app
    uvicorn.run("FasterAPI:app", host="127.0.0.1", log_level="info", reload=True)

Finally, you could start the application by simply run the main.py.

Add additonal models and routes

If you need more models, you have to reference the base created inside FasterAPI:

from FasterAPI import Base

For your additional route, you have to reference the FasterAPI app instance like:

from FasterAPI.app import app

@app.get("/)
# your function goes here

Note that you will have to create a python module, place main.py and auth-config.yaml like following:

your_module:
  -- __init__.py
  -- models.py # your additional models
  -- schemas.py # your schemas
  -- routes.py # your addtional routes
main.py
auth_config.yaml

You can add meta data with "meta_config.yaml"

For example, the following "meta_config.yaml" will change the title and version, as well as enable the debug.

DEBUG: True
TITLE: "My API"
DESCRIPTION: "This is a description of my API"
VERSION: "0.0.2"
OPENAPI_URL: "/openapi.json"
DOCS_URL: "/docs"
REDOC_URL: "/redoc"
TERMS_OF_SERVICE: ""
CONTACT: ""
SUMMARY: "This is a summary of my API"

All the key words here is simply one to one mapping of FastAPI() constructor!

New! Now also built in with Opentelemetries for Tracing!, simple configure the following in meta_config.yaml

JAEGER_SVC_NAME: "my-api" # service name
JAEGER_TRACE: True # enable tracing
JAEGER_HOST: "localhost" # Jaeger host
JAEGER_PORT: "6831" # Jaeger host port

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

fasterapi-0.0.46.tar.gz (16.3 kB view details)

Uploaded Source

Built Distribution

fasterapi-0.0.46-py3-none-any.whl (19.1 kB view details)

Uploaded Python 3

File details

Details for the file fasterapi-0.0.46.tar.gz.

File metadata

  • Download URL: fasterapi-0.0.46.tar.gz
  • Upload date:
  • Size: 16.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.3 CPython/3.12.6 Windows/11

File hashes

Hashes for fasterapi-0.0.46.tar.gz
Algorithm Hash digest
SHA256 bbb5c3af6f12c8122ca7516925664903a3745e5369e85bad87859ba9468ed699
MD5 7dc25fee07a4b1e84a3d12f32eaa4c5b
BLAKE2b-256 3e00330146d1fbba97f4d61d23434bfe4761acfda32ce6415f08258157815d77

See more details on using hashes here.

File details

Details for the file fasterapi-0.0.46-py3-none-any.whl.

File metadata

  • Download URL: fasterapi-0.0.46-py3-none-any.whl
  • Upload date:
  • Size: 19.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.3 CPython/3.12.6 Windows/11

File hashes

Hashes for fasterapi-0.0.46-py3-none-any.whl
Algorithm Hash digest
SHA256 c0687acd72896966cd7090ddac959cd1ff1f955fb4231d4378ef43b1e397a674
MD5 0734de2e77432c8bc1edb35d877805c6
BLAKE2b-256 95cdbdfc45e595f6f010f232ec80c0c3f4ff90700ed5b0e95be19610c7df065e

See more details on using hashes here.

Supported by

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