fastapi-standalone-docs


Namefastapi-standalone-docs JSON
Version 0.1.5 PyPI version JSON
download
home_pagehttps://github.com/ioxiocom/fastapi-standalone-docs
SummaryHost FastAPI Swagger UI and ReDoc without third party CDNs
upload_time2023-07-13 13:36:56
maintainer
docs_urlNone
authorIOXIO Ltd
requires_python>=3.8.1,<4.0
licenseMIT
keywords
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # FastAPI Standalone Docs

[![GitHub Workflow Status](https://img.shields.io/github/actions/workflow/status/ioxiocom/fastapi-standalone-docs/publish.yaml)](https://github.com/ioxiocom/fastapi-standalone-docs/actions/workflows/publish.yaml)
[![Code style: black](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/psf/black)
[![PyPI](https://img.shields.io/pypi/v/fastapi-standalone-docs)](https://pypi.org/project/fastapi-standalone-docs/)
[![PyPI - Python Version](https://img.shields.io/pypi/pyversions/fastapi-standalone-docs)](https://pypi.org/project/fastapi-standalone-docs/)
[![License: MIT](https://img.shields.io/pypi/l/fastapi-standalone-docs)](https://opensource.org/license/mit/)

Host FastAPI Swagger UI and ReDoc without any third party CDNs. Handy if you want to be
able to use the docs offline or want to avoid loading content from 3rd party CDNs due to
privacy reasons.

This library was heavily inspired by
[fastapi-offline-swagger-ui](https://github.com/ahmetoner/fastapi-offline-swagger-ui),
but we wanted a way to take it into use with less boilerplate code and also have it
hosted on PyPI.

## Installation

The package is available on PyPI:

```bash
pip install fastapi-standalone-docs
```

## Usage

Import `StandaloneDocs` and pass in the FastAPI application to it:

```python
from fastapi import FastAPI
from fastapi_standalone_docs import StandaloneDocs

app = FastAPI()
StandaloneDocs(app=app)
```

The static files will by default be served from subpaths of the `docs_url` and
`redoc_url` as you've specified in your FastAPI app. The library doesn't make any
assumption on any particular path being reserved for the library. And if you disable
either of the two UIs, the corresponding files won't either be served unnecessarily.

This example would move the Swagger UI and the static files needed for it to the path
`/swagger` and disable the ReDoc interface and the static files needed by it:

```python
from fastapi import FastAPI
from fastapi_standalone_docs import StandaloneDocs

app = FastAPI(docs_url="/swagger", redoc_url=None)
StandaloneDocs(app=app)
```

By default, the library will use the FastAPI favicons, and they're served from
`{docs_url}/fastapi/favicon.png` and `{redoc_url}/fastapi/favicon.png`. You can use your
own favicons like this, which will also disable the FastAPI icons:

```python
from fastapi import FastAPI
from fastapi_standalone_docs import StandaloneDocs

app = FastAPI()
StandaloneDocs(
    app=app,
    redoc_favicon_url="/favicon.png",
    swagger_favicon_url="/favicon.png",
)
```

To make the docs truly stand alone the Google Fonts are by default disabled (they are
used in the ReDoc interface). If you want to enable them just set
`with_google_fonts=True`, like this:

```python
from fastapi import FastAPI
from fastapi_standalone_docs import StandaloneDocs

app = FastAPI()
StandaloneDocs(
    app=app,
    with_google_fonts=True,
)
```

### Disclaimer

**Note!** If you create multiple FastAPI apps in the same runtime (quite unlikely
use-case), using StandaloneDocs on one of them will affect the other ones as well, as
the library patches two of the shared functions (`get_swagger_ui_html` and
`get_redoc_html`). Thus the library should not be used in a such setup unless all the
apps will use StandaloneDocs with the same settings.

## Development

PRs are welcome!

This project is using [Poetry](https://python-poetry.org/) and
[pre-commit](https://pre-commit.com/), so please ensure you've installed both. To set up
the project with them run:

```bash
pre-commit install
poetry install
```

Running tests locally:

```bash
poetry run invoke test
```

Updating the static files from the CDNs:

```bash
poetry run update-fastapi-standalone-docs
```

If you want to test using it locally in some other project, in that project run this
(make sure to adjust the path to the local repo):

```bash
poetry add ../fastapi-standalone-docs --editable
```

## License

The code of this library itself is released under the [MIT license](./LICENSE). Please
however note that this library also contains parts of
[ReDoc](./fastapi_standalone_docs/static/redoc/), which is licensed under the
[MIT license](./fastapi_standalone_docs/static/redoc/redoc.standalone.js.LICENSE.txt),
[Swagger UI](./fastapi_standalone_docs/static/swagger/), which is licensed under the
[Apache 2.0 License](./fastapi_standalone_docs/static/swagger/LICENSE), as well as parts
of [FastAPI](./fastapi_standalone_docs/static/fastapi) (the favicon), which is licensed
under the [MIT license](./fastapi_standalone_docs/static/fastapi/LICENSE).

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/ioxiocom/fastapi-standalone-docs",
    "name": "fastapi-standalone-docs",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.8.1,<4.0",
    "maintainer_email": "",
    "keywords": "",
    "author": "IOXIO Ltd",
    "author_email": "",
    "download_url": "https://files.pythonhosted.org/packages/4e/67/ac778e6a9539189b7bc12a48d21bad6966d4b718d764ec9b2b601ff99ee0/fastapi_standalone_docs-0.1.5.tar.gz",
    "platform": null,
    "description": "# FastAPI Standalone Docs\n\n[![GitHub Workflow Status](https://img.shields.io/github/actions/workflow/status/ioxiocom/fastapi-standalone-docs/publish.yaml)](https://github.com/ioxiocom/fastapi-standalone-docs/actions/workflows/publish.yaml)\n[![Code style: black](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/psf/black)\n[![PyPI](https://img.shields.io/pypi/v/fastapi-standalone-docs)](https://pypi.org/project/fastapi-standalone-docs/)\n[![PyPI - Python Version](https://img.shields.io/pypi/pyversions/fastapi-standalone-docs)](https://pypi.org/project/fastapi-standalone-docs/)\n[![License: MIT](https://img.shields.io/pypi/l/fastapi-standalone-docs)](https://opensource.org/license/mit/)\n\nHost FastAPI Swagger UI and ReDoc without any third party CDNs. Handy if you want to be\nable to use the docs offline or want to avoid loading content from 3rd party CDNs due to\nprivacy reasons.\n\nThis library was heavily inspired by\n[fastapi-offline-swagger-ui](https://github.com/ahmetoner/fastapi-offline-swagger-ui),\nbut we wanted a way to take it into use with less boilerplate code and also have it\nhosted on PyPI.\n\n## Installation\n\nThe package is available on PyPI:\n\n```bash\npip install fastapi-standalone-docs\n```\n\n## Usage\n\nImport `StandaloneDocs` and pass in the FastAPI application to it:\n\n```python\nfrom fastapi import FastAPI\nfrom fastapi_standalone_docs import StandaloneDocs\n\napp = FastAPI()\nStandaloneDocs(app=app)\n```\n\nThe static files will by default be served from subpaths of the `docs_url` and\n`redoc_url` as you've specified in your FastAPI app. The library doesn't make any\nassumption on any particular path being reserved for the library. And if you disable\neither of the two UIs, the corresponding files won't either be served unnecessarily.\n\nThis example would move the Swagger UI and the static files needed for it to the path\n`/swagger` and disable the ReDoc interface and the static files needed by it:\n\n```python\nfrom fastapi import FastAPI\nfrom fastapi_standalone_docs import StandaloneDocs\n\napp = FastAPI(docs_url=\"/swagger\", redoc_url=None)\nStandaloneDocs(app=app)\n```\n\nBy default, the library will use the FastAPI favicons, and they're served from\n`{docs_url}/fastapi/favicon.png` and `{redoc_url}/fastapi/favicon.png`. You can use your\nown favicons like this, which will also disable the FastAPI icons:\n\n```python\nfrom fastapi import FastAPI\nfrom fastapi_standalone_docs import StandaloneDocs\n\napp = FastAPI()\nStandaloneDocs(\n    app=app,\n    redoc_favicon_url=\"/favicon.png\",\n    swagger_favicon_url=\"/favicon.png\",\n)\n```\n\nTo make the docs truly stand alone the Google Fonts are by default disabled (they are\nused in the ReDoc interface). If you want to enable them just set\n`with_google_fonts=True`, like this:\n\n```python\nfrom fastapi import FastAPI\nfrom fastapi_standalone_docs import StandaloneDocs\n\napp = FastAPI()\nStandaloneDocs(\n    app=app,\n    with_google_fonts=True,\n)\n```\n\n### Disclaimer\n\n**Note!** If you create multiple FastAPI apps in the same runtime (quite unlikely\nuse-case), using StandaloneDocs on one of them will affect the other ones as well, as\nthe library patches two of the shared functions (`get_swagger_ui_html` and\n`get_redoc_html`). Thus the library should not be used in a such setup unless all the\napps will use StandaloneDocs with the same settings.\n\n## Development\n\nPRs are welcome!\n\nThis project is using [Poetry](https://python-poetry.org/) and\n[pre-commit](https://pre-commit.com/), so please ensure you've installed both. To set up\nthe project with them run:\n\n```bash\npre-commit install\npoetry install\n```\n\nRunning tests locally:\n\n```bash\npoetry run invoke test\n```\n\nUpdating the static files from the CDNs:\n\n```bash\npoetry run update-fastapi-standalone-docs\n```\n\nIf you want to test using it locally in some other project, in that project run this\n(make sure to adjust the path to the local repo):\n\n```bash\npoetry add ../fastapi-standalone-docs --editable\n```\n\n## License\n\nThe code of this library itself is released under the [MIT license](./LICENSE). Please\nhowever note that this library also contains parts of\n[ReDoc](./fastapi_standalone_docs/static/redoc/), which is licensed under the\n[MIT license](./fastapi_standalone_docs/static/redoc/redoc.standalone.js.LICENSE.txt),\n[Swagger UI](./fastapi_standalone_docs/static/swagger/), which is licensed under the\n[Apache 2.0 License](./fastapi_standalone_docs/static/swagger/LICENSE), as well as parts\nof [FastAPI](./fastapi_standalone_docs/static/fastapi) (the favicon), which is licensed\nunder the [MIT license](./fastapi_standalone_docs/static/fastapi/LICENSE).\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "Host FastAPI Swagger UI and ReDoc without third party CDNs",
    "version": "0.1.5",
    "project_urls": {
        "Homepage": "https://github.com/ioxiocom/fastapi-standalone-docs",
        "Repository": "https://github.com/ioxiocom/fastapi-standalone-docs"
    },
    "split_keywords": [],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "5ebcc5a745fdd34308b227fc17c16b87cbfe4ecdb9c55648c9bf9bca8f1e8635",
                "md5": "8b08b367dfa3ac359eb039b28fb099ed",
                "sha256": "9808eb1dba13c50ed3501ca5e7b3d4c3699732698f87b781bedaf5314036f2bd"
            },
            "downloads": -1,
            "filename": "fastapi_standalone_docs-0.1.5-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "8b08b367dfa3ac359eb039b28fb099ed",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.8.1,<4.0",
            "size": 1113027,
            "upload_time": "2023-07-13T13:36:54",
            "upload_time_iso_8601": "2023-07-13T13:36:54.382204Z",
            "url": "https://files.pythonhosted.org/packages/5e/bc/c5a745fdd34308b227fc17c16b87cbfe4ecdb9c55648c9bf9bca8f1e8635/fastapi_standalone_docs-0.1.5-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "4e67ac778e6a9539189b7bc12a48d21bad6966d4b718d764ec9b2b601ff99ee0",
                "md5": "2340cd553dfdfd17ef4d7c9b2042cdf2",
                "sha256": "a4ebcedfe7512d05adb03a2ed7e984d92aa5d069adbd4fc660af4da1b606096a"
            },
            "downloads": -1,
            "filename": "fastapi_standalone_docs-0.1.5.tar.gz",
            "has_sig": false,
            "md5_digest": "2340cd553dfdfd17ef4d7c9b2042cdf2",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.8.1,<4.0",
            "size": 1106726,
            "upload_time": "2023-07-13T13:36:56",
            "upload_time_iso_8601": "2023-07-13T13:36:56.206951Z",
            "url": "https://files.pythonhosted.org/packages/4e/67/ac778e6a9539189b7bc12a48d21bad6966d4b718d764ec9b2b601ff99ee0/fastapi_standalone_docs-0.1.5.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-07-13 13:36:56",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "ioxiocom",
    "github_project": "fastapi-standalone-docs",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "lcname": "fastapi-standalone-docs"
}
        
Elapsed time: 0.29669s