Skip to main content

HTTP/WebSocket proxy for starlette/FastAPI.

Project description

FastAPI Proxy Lib

HTTP/WebSocket proxy for starlette/FastAPI

CI/CD CI: lint-test pre-commit.ci status
CI: docs CI: publish
Code codecov Code style: black Ruff Checked with pyright
Package PyPI - Version PyPI - Downloads PyPI - Python Version
Meta Hatch project GitHub License

Documentation: https://wsh032.github.io/fastapi-proxy-lib/

Source Code: https://github.com/WSH032/fastapi-proxy-lib/


Features

  • Out of the box ! Helper functions to get FastAPI app/router for proxy conveniently.
  • Only Starlette is required for it to work (FastAPI is optional).
  • Support both HTTP and WebSocket proxy.
    • Supports all HTTP methods (GET, POST, etc.)
  • Support both reverse proxy and forward proxy.
  • Transparently and losslessly handle all proxy requests, Including HTTP headers, cookies, query parameters, body, etc.
  • Asynchronous streaming transfer, support file proxy.
  • fastapi-proxy-lib value privacy security.

other features

  • Strict linting and strict-mode Pyright type checking.
  • 100% Type Completeness, Code coverage of over 95%.
  • Forced keep-alive connections, minimizing proxy latency.
  • Handle errors as gracefully as possible.
    • fastapi-proxy-lib has a well-designed mechanism behind the scenes to handle exceptional websocket disconnections for you.
    • fastapi-proxy-lib will exit as gracefully as possible.

FastAPI Proxy Lib stands on the shoulders of giants

So, it perfectly supports all features of httpx.AsyncClient, you can even use your custom AsyncClient, Transport.

See Advanced Usage for more details.

except cookies and base_url arguments, which are taken over by fastapi-proxy-lib

Installation

!!! note

We follow semantic versioning.<br>
This is a young project, and before 1.0.0, there may be changes in the API (we try to avoid that).<br>
We will release security updates at any time, please try to keep the version updated, instead of pinning to the old version.<br>
pin to `major version` is recommended.<br>
visit our `CHANGELOG.md` for more info.
pip install fastapi-proxy-lib[standard]

Perhaps you've noticed that we're installing fastapi-proxy-lib[standard] instead of fastapi-proxy-lib. The difference is:

  • The former will install FastAPI at the same time.
  • The latter installs only the basic dependencies for fastapi-proxy-lib.

If you only need to use this library with Starlette, you only need to install the latter.

Quick start

With the helper functions, get the FastAPI proxy server app is very convenient and out of the box:

from fastapi_proxy_lib.fastapi.app import reverse_http_app

app = reverse_http_app(base_url="http://www.example.com/foo/")

That's all! Now, you can launch the proxy server with uvicorn:

uvicorn main:app  --host 127.0.0.1 --port 8000

Then, visit http://127.0.0.1:8000/bar?baz=1, you will get the response from http://www.example.com/foo/bar?baz=1.

Continue, please visit to our documentation 📚 for more details:

  • support for FastAPI router
  • only Starlette dependency
  • WebSocket proxy

development

English is not the native language of the author (me), so if you find any areas for improvement in the documentation, your feedback is welcome.

If you think this project helpful, consider giving it a star GitHub Repo stars, which makes me happy. :smile:

Refers

Can fastapi proxy another site as a response to the request?

License

This project is licensed under the terms of the Apache License 2.0.

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

fastapi_proxy_lib-0.3.0.tar.gz (63.2 kB view details)

Uploaded Source

Built Distribution

fastapi_proxy_lib-0.3.0-py3-none-any.whl (41.2 kB view details)

Uploaded Python 3

File details

Details for the file fastapi_proxy_lib-0.3.0.tar.gz.

File metadata

  • Download URL: fastapi_proxy_lib-0.3.0.tar.gz
  • Upload date:
  • Size: 63.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for fastapi_proxy_lib-0.3.0.tar.gz
Algorithm Hash digest
SHA256 c311b64f335624babc4ca61551f9468b9cfe49adeb7a752ce798e5090e466232
MD5 9e3969ced512679487f4a005f66b25ac
BLAKE2b-256 4c947d50fca4480d579fcc7eb19379e2f82e136420ab2e2cfa91b60a426b506c

See more details on using hashes here.

Provenance

The following attestation bundles were made for fastapi_proxy_lib-0.3.0.tar.gz:

Publisher: publish.yml on WSH032/fastapi-proxy-lib

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file fastapi_proxy_lib-0.3.0-py3-none-any.whl.

File metadata

File hashes

Hashes for fastapi_proxy_lib-0.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 7b757f7ad08630c7422574fa0d1c650bd1899b77798187438b4b1fe38ee143ca
MD5 cbd3e05ac59ce6e2213888f8181a79ae
BLAKE2b-256 6fe13771bb626bcb3ff9d31bb2331996f928c44092f45373b600adb67dacf267

See more details on using hashes here.

Provenance

The following attestation bundles were made for fastapi_proxy_lib-0.3.0-py3-none-any.whl:

Publisher: publish.yml on WSH032/fastapi-proxy-lib

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

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