|
1 |
| -Documentation is coming, please use [API Reference](https://WSH032.github.io/fastapi-proxy-lib/) first. :smile: |
| 1 | +# FastAPI Proxy Lib |
| 2 | + |
| 3 | +<p align="center"> |
| 4 | + <em>HTTP/WebSocket proxy for starlette/FastAPI</em> |
| 5 | +</p> |
| 6 | + |
| 7 | +| | | |
| 8 | +| ------- | --------------------------------------------------------------------------------------------------------------------------------------------------- | |
| 9 | +| CI/CD | [![CI: lint-test]][CI: lint-test#link] [![CI: docs]][CI: docs#link] | |
| 10 | +| Code | [![codecov]][codecov#link] [![Code style: black]][Code style: black#link] [![Ruff]][Ruff#link] [![Checked with pyright]][Checked with pyright#link] | |
| 11 | +| Package | [![Python-Version]][Python-Version#link] | |
| 12 | +| Meta | [![Hatch project]][Hatch project#link] [![GitHub License]][GitHub License#link] | |
| 13 | + |
| 14 | +--- |
| 15 | + |
| 16 | +Documentation: <https://wsh032.github.io/fastapi-proxy-lib/> |
| 17 | + |
| 18 | +Source Code: <https://github.com/WSH032/fastapi-proxy-lib/> |
| 19 | + |
| 20 | +--- |
| 21 | + |
| 22 | +## Features |
| 23 | + |
| 24 | +- [X] **Out of the box !** [Helper functions](#quick-start) to get FastAPI `app`/`router` for proxy conveniently. |
| 25 | +- [x] **Only `Starlette` is required** for it to work ([`FastAPI` is optional](#installation)). |
| 26 | +- [x] Support both **HTTP** and **WebSocket** proxy. |
| 27 | + - [x] Supports all HTTP methods (`GET`, `POST`, etc.) |
| 28 | +- [x] Support both **reverse** proxy and **forward** proxy. |
| 29 | +- [x] **Transparently** and **losslessly** handle all proxy requests, |
| 30 | +- [x] Asynchronous streaming transfer, support **file proxy**. |
| 31 | + |
| 32 | +### other features |
| 33 | + |
| 34 | +- [x] Strict linting and strict-mode Pyright type checking. |
| 35 | +- [x] **100%** [Type Completeness](https://microsoft.github.io/pyright/#/typed-libraries?id=type-completeness), [Code coverage of **over 95%**][codecov#link]. |
| 36 | +- [x] Forced keep-alive connections, minimizing proxy latency. |
| 37 | +- [x] Handle errors as gracefully as possible. |
| 38 | + |
| 39 | +### `FastAPI Proxy Lib` stands on the shoulders of giants |
| 40 | + |
| 41 | +- [httpx](https://github.com/encode/httpx) for HTTP proxy |
| 42 | +- [httpx-ws](https://github.com/frankie567/httpx-ws) for WebSocket proxy |
| 43 | + |
| 44 | +So, it perfectly supports all features of [httpx.AsyncClient](https://www.python-httpx.org/advanced/#client-instances), you can even use your custom `AsyncClient`, [`Transport`](https://www.python-httpx.org/advanced/#custom-transports). |
| 45 | + |
| 46 | +## Installation |
| 47 | + |
| 48 | +> !!! note |
| 49 | +> |
| 50 | +> We follow semantic versioning.<br> |
| 51 | +> This is a young project, and before 1.0.0, there may be changes in the API (though we try to avoid that).<br> |
| 52 | +> We recommend pinning to any minor versions, such as 0.1.x. |
| 53 | +
|
| 54 | +Pypi will come soon, please install from github temporarily: |
| 55 | + |
| 56 | +```shell |
| 57 | +pip install fastapi-proxy-lib[standard]@git+https://github.com/WSH032/fastapi-proxy-lib.git |
| 58 | +``` |
| 59 | + |
| 60 | +Perhaps you've noticed that we're installing `fastapi-proxy-lib[standard]` instead of `fastapi-proxy-lib`. The difference is: |
| 61 | + |
| 62 | +- The former will install `FastAPI` at the same time. |
| 63 | +- The latter installs only the basic dependencies for `fastapi-proxy-lib`. |
| 64 | + |
| 65 | +If you **only need to use this library with Starlette**, you only need to install the latter. |
| 66 | + |
| 67 | +## Quick start |
| 68 | + |
| 69 | +With the helper functions, get the FastAPI proxy server app is very convenient and out of the box: |
| 70 | + |
| 71 | +```python |
| 72 | +from fastapi_proxy_lib.fastapi.app import reverse_http_app |
| 73 | + |
| 74 | +app = reverse_http_app(base_url="http://www.example.com/foo/") |
| 75 | +``` |
| 76 | + |
| 77 | +That's all! Now, you can launch the proxy server with `uvicorn`: |
| 78 | + |
| 79 | +```shell |
| 80 | +uvicorn main:app --host 127.0.0.1 --port 8000 |
| 81 | +``` |
| 82 | + |
| 83 | +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`. |
| 84 | + |
| 85 | +For support with `FastAPI router` or only using `Starlette`, please **visit to our [documentation 📚](https://wsh032.github.io/fastapi-proxy-lib/) for more details**. |
| 86 | + |
| 87 | +## development |
| 88 | + |
| 89 | +- If you find any issues, please don't hesitate to [open an issue](https://github.com/WSH032/fastapi-proxy-lib/issues). |
| 90 | +- If you need assistance, feel free to [start a discussion](https://github.com/WSH032/fastapi-proxy-lib/discussions). |
| 91 | +- [Welcome PR](https://github.com/WSH032/fastapi-proxy-lib/pulls) |
| 92 | + |
| 93 | +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. |
| 94 | + |
| 95 | +If you think this project helpful, consider giving it a star  |
| 96 | + , which makes me happy. :smile: |
| 97 | + |
| 98 | +## License |
| 99 | + |
| 100 | +This project is licensed under the terms of the *Apache License 2.0*. |
| 101 | + |
| 102 | +<!-- link --> |
| 103 | + |
| 104 | +[CI: lint-test]: https://github.com/WSH032/fastapi-proxy-lib/actions/workflows/lint-test.yml/badge.svg?branch=main |
| 105 | +[CI: lint-test#link]: https://github.com/WSH032/fastapi-proxy-lib/actions/workflows/lint-test.yml |
| 106 | +[CI: docs]: https://github.com/WSH032/fastapi-proxy-lib/actions/workflows/docs.yml/badge.svg?branch=main |
| 107 | +[CI: docs#link]: https://github.com/WSH032/fastapi-proxy-lib/actions/workflows/docs.yml |
| 108 | +[Python-Version]: https://img.shields.io/python/required-version-toml?tomlFilePath=https%3A%2F%2Fraw.githubusercontent.com%2FWSH032%2Ffastapi-proxy%2Fmain%2Fpyproject.toml&logo=python&logoColor=gold&label=Python |
| 109 | +[Python-Version#link]: https://github.com/WSH032/fastapi-proxy-lib/blob/main/pyproject.toml |
| 110 | +[Code style: black]: https://img.shields.io/badge/code%20style-black-000000.svg |
| 111 | +[Code style: black#link]: https://github.com/psf/black |
| 112 | +[GitHub License]: https://img.shields.io/github/license/WSH032/fastapi-proxy-lib?color=9400d3 |
| 113 | +[GitHub License#link]: https://github.com/WSH032/fastapi-proxy-lib/blob/main/LICENSE |
| 114 | +[Ruff]: https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/astral-sh/ruff/main/assets/badge/v2.json |
| 115 | +[Ruff#link]: https://github.com/astral-sh/ruff |
| 116 | +[Checked with pyright]: https://microsoft.github.io/pyright/img/pyright_badge.svg |
| 117 | +[Checked with pyright#link]: https://microsoft.github.io/pyright |
| 118 | +[Hatch project]: https://img.shields.io/badge/%F0%9F%A5%9A-Hatch-4051b5.svg |
| 119 | +[Hatch project#link]: https://github.com/pypa/hatch |
| 120 | +[codecov]: https://codecov.io/gh/WSH032/fastapi-proxy-lib/graph/badge.svg?token=62QQU06E8X |
| 121 | +[codecov#link]: https://codecov.io/gh/WSH032/fastapi-proxy-lib |
0 commit comments