Skip to main content

Build FastAPI app top of Django

Project description

Django FastAPI

Allows to use FastAPI top of Django

Quickstart

Install required packages:

pip install django-fastapi 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.post2.tar.gz (4.2 kB view hashes)

Uploaded Source

Built Distribution

django_fastapi_bridge-0.1.post2-py3-none-any.whl (6.3 kB view hashes)

Uploaded Python 3

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