Skip to main content

Build FastAPI app top of Django

Project description

Django FastAPI Bridge

Allows to use FastAPI top of Django

Quickstart

Install FastAPI:

pip install fastapi

Install required packages:

pip install django-fastapi-bridge daphne

Note that daphne is required only for changing runserver command to work with ASGI. It is not required for production usage.

Add django_fastapi and daphne to INSTALLED_APPS in your settings.py file:

INSTALLED_APPS = [
    # ...
    "daphne",  # must be before django.cotrib.staticfiles
    "django.contrib.staticfiles",
    # ...
    "django_fastapi",
]

Set ASGI_APPLICATION in your settings.py file:

ASGI_APPLICATION = "django_fastapi.asgi.application"

Development server (ASGI w/Daphne)

Run development server:

python manage.py runserver

Production server (ASGI w/Uvicorn)

Install Uvicorn:

pip install uvicorn

Run uvicorn:

DJANGO_SETTINGS_MODULE=yourproject.settings uvicorn django_fastapi.asgi:application

Configuration

Base settings

To configure default FastAPI instance you can use these settings:

  • FASTAPI_TITLE: set's API title [FastAPI(title=FASTAPI_TITLE)]
  • FASTAPI_VERSION: set's API version [FastAPI(version=FASTAPI_VERSION)]
  • FASTAPI_ROOT_PATH: set's API root path [FastAPI(root_path=FASTAPI_ROOT_PATH)]

CORS

  • FASTAPI_CORS_ENABLED: if True, adds CORS middleware to the default FastAPI instance (disabled by default)
  • FASTAPI_CORS_ALLOW_ORIGINS: defaults to ["*"]
  • FASTAPI_CORS_ALLOW_CREDENTIALS: defaults to True
  • FASTAPI_CORS_ALLOW_METHODS: defaults to ["*"]
  • FASTAPI_CORS_ALLOW_HEADERS: defaults to ["*"]

Autodiscover

  • FASTAPI_AUTODISCOVER: if True, Django FastAPI will automatically import FASTAPI_AUTODISCOVER_MODULES from your INSTALLED_APPS. Default: True
  • FASTAPI_AUTODISCOVER_MODULES: defaults to ["api"]

License

ISC

Copyright 2023 Marcin Nowak <marcin.j.nowak.gmail.com>

Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted, provided that the above copyright notice and this permission notice appear in all copies.

THE SOFTWARE IS PROVIDED “AS IS” AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.

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

django-fastapi-bridge-0.1.post4.tar.gz (4.2 kB view details)

Uploaded Source

Built Distribution

File details

Details for the file django-fastapi-bridge-0.1.post4.tar.gz.

File metadata

File hashes

Hashes for django-fastapi-bridge-0.1.post4.tar.gz
Algorithm Hash digest
SHA256 0ea3140609d8546991f3d598f157791d0c8e37b0b654d257f2ffed428d80a184
MD5 3911af72e059e1dd58c1f62b4e6d981d
BLAKE2b-256 3cd53a8e13ee5c741dab60e5e68d5bec6aac72ae45931f4858ecc84d1fd9d28e

See more details on using hashes here.

File details

Details for the file django_fastapi_bridge-0.1.post4-py3-none-any.whl.

File metadata

File hashes

Hashes for django_fastapi_bridge-0.1.post4-py3-none-any.whl
Algorithm Hash digest
SHA256 b39c50c17ccb6531301c8391053bd803313e658ef038ca4e315112b2e45e6fd6
MD5 1a9c843c8a4daa371c98f17cc1663be6
BLAKE2b-256 1472953ced0a64e8f5e867e5a19c3f230fc13cb11c0aea230a954eb324cb9b1d

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