Skip to main content

Fastapi integration for rewire

Project description

rewire_fastapi

A FastAPI integration for rewire.

Installation

To get started, install rewire_fastapi using pip:

pip install rewire_fastapi

Supported Servers

This package supports running with both Uvicorn and Hypercorn servers (rewire_fastapi.server).

Usage

First, import add rewire_fastapi to your rewire application:

# ...
import rewire_fastapi

async def main():
    async with Space().init().use():
        DependenciesModule.get().add(rewire_fastapi.plugin)  # add this
        # ...

Then have injected fastapi in your files:

from fastapi import APIRouter, FastAPI
from rewire.plugins import simple_plugin

plugin = simple_plugin()
router = APIRouter()


@router.get("/hello")
def hello_world():
    return "world"


@plugin.setup()
async def include_router(app: FastAPI):
    app.include_router(router)

Configuration

Configure the package in config.yaml file:

rewire_fastapi:
  server: "hypercorn"
  app: # will be passed to FastAPI instance
    title: "My App"
  uvicorn: # (optional)
    port: 1234
  hypercorn: # (optional)
    bind: "0.0.0.0:1234"
  routes:  # (optional)
    tag_prefix: "myapp:"
  patch: # (optional)
    swagger_hierarchical_tags: true
    tag_prefixes: true
  middleware:
    cors: # enable cors middleware (optional)
      allow_origins: ["*"]
      allow_methods: ["*"]
      allow_headers: ["*"]

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

rewire_fastapi-0.1.2.tar.gz (5.6 kB view details)

Uploaded Source

Built Distribution

rewire_fastapi-0.1.2-py3-none-any.whl (6.7 kB view details)

Uploaded Python 3

File details

Details for the file rewire_fastapi-0.1.2.tar.gz.

File metadata

  • Download URL: rewire_fastapi-0.1.2.tar.gz
  • Upload date:
  • Size: 5.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.12.1

File hashes

Hashes for rewire_fastapi-0.1.2.tar.gz
Algorithm Hash digest
SHA256 268a3c6eb4968c31eb7c5dacf55a61234d943fa349c53238b2511c45669f1c4a
MD5 d3df6626bdb3da9e69b7b6130ed886c3
BLAKE2b-256 d798a1a86f57d0ef6407e0270fbfe9762265326d8182e0b2ac827bb5973cbdc0

See more details on using hashes here.

File details

Details for the file rewire_fastapi-0.1.2-py3-none-any.whl.

File metadata

File hashes

Hashes for rewire_fastapi-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 f1131b75e80ed6c67b7e2b0b77c0b0e1651576fe63286f65183bc0959a2ed0dc
MD5 b5e695087e7d4f2abd30c1491d6a024a
BLAKE2b-256 b68cd3720dfb01c26ae46577a11fc746dd06d20f20df79e8920b7660534bf2bb

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