fastapi-tailwind


Namefastapi-tailwind JSON
Version 1.0.1a7 PyPI version JSON
download
home_pageNone
Summary✨ TailwindCSS support for 🔥 FastAPI.
upload_time2024-09-04 20:40:30
maintainerNone
docs_urlNone
authorNone
requires_python>=3.8
licenseMIT License Copyright (c) 2024-present Goldy Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
keywords tailwindcss tailwind fastapi fastapi middleware
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            <div align="center">

  # ✨ 🔥 fastapi-tailwind

  <sub>Streamlined approach for adding TailwindCSS to FastAPI **without** NodeJS.</sub>

  <img src="./assets/heart_banner_cropped.png">

</div>

> [!WARNING]
> Currently in testing phase so expect bugs but do report them please. 🙏

## Features ✨
- [x] Auto watch when in dev mode. 🔎
- [x] Doesn't require NodeJS and NPM. 🫧🪥
- [x] Seemless integration into the FastAPI codebase. 🥂
- [ ] GZIP automatically configured to [compress TailwindCSS](https://v1.tailwindcss.com/docs/controlling-file-size) out of the box. ⚡

## How to add?
> [!NOTE]
> These instructions assume you have a somewhat intermediate understanding of FastAPI and that you've used TailwindCSS before (if you haven't be sure to read the documentation I link in tailwind stages) as I may assume some things.

1. Install the pypi package.
```sh
pip install fastapi-tailwind
```
2. Edit your FastAPI APP.

Before:
```python
from fastapi import FastAPI
from fastapi.responses import FileResponse
from fastapi.staticfiles import StaticFiles

app = FastAPI()

@app.get("/")
def index():
    return FileResponse("./index.html")

app.mount("/static", StaticFiles(directory = "static"), name = "static")
```

After:
```python
# main.py

from fastapi import FastAPI
from fastapi.responses import FileResponse
from fastapi.staticfiles import StaticFiles

from fastapi_tailwind import tailwind
from contextlib import asynccontextmanager

static_files = StaticFiles(directory = "static")

@asynccontextmanager
async def lifespan(app: FastAPI):
    # YAY, our tailwind get's compiled here! 😄
    process = tailwind.compile(static_files.directory + "/output.css")

    yield # The code after this is called on shutdown.

    process.terminate() # We must terminate the compiler on shutdown to
    # prevent multiple compilers running in development mode or when watch is enabled.

app = FastAPI(
    # See the fastapi documentation for an explanation on lifespans: https://fastapi.tiangolo.com/advanced/events/
    lifespan = lifespan
)

@app.get("/")
def index():
    return FileResponse("./index.html")

# We need somewhere to drop the compiled stylesheet so our html file can link it.
app.mount("/static", static_files, name = "static")
```

3. Make sure the `static` folder exists.
```sh
mkdir ./static
```
4. Generate `tailwind.config.js`, then [configure it](https://tailwindcss.com/docs/configuration) appropriately.
```sh
fastapi-tailwind-init
```
5. Write your tailwind css in `index.html`.
```html
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>✨ Tailwind in 🔥 FastAPI</title>

    <link rel="stylesheet" href="/static/output.css">
</head>
<body class="bg-slate-950">
    <h1 class="mt-10 text-center text-6xl font-bold text-red-400">👋 Hello ✨ Tailwind!</h1>
</body>
</html>
```
6. Run FastAPI and visit your site.
```sh
fastapi dev main.py
```
<div align="center">

  <img width="800px" src="./assets/example_page_showcase.png">

</div>

            

Raw data

            {
    "_id": null,
    "home_page": null,
    "name": "fastapi-tailwind",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.8",
    "maintainer_email": null,
    "keywords": "tailwindcss, tailwind, fastapi, fastapi middleware",
    "author": null,
    "author_email": "Goldy <goldy@devgoldy.xyz>",
    "download_url": null,
    "platform": null,
    "description": "<div align=\"center\">\n\n  # \u2728 \ud83d\udd25 fastapi-tailwind\n\n  <sub>Streamlined approach for adding TailwindCSS to FastAPI **without** NodeJS.</sub>\n\n  <img src=\"./assets/heart_banner_cropped.png\">\n\n</div>\n\n> [!WARNING]\n> Currently in testing phase so expect bugs but do report them please. \ud83d\ude4f\n\n## Features \u2728\n- [x] Auto watch when in dev mode. \ud83d\udd0e\n- [x] Doesn't require NodeJS and NPM. \ud83e\udee7\ud83e\udea5\n- [x] Seemless integration into the FastAPI codebase. \ud83e\udd42\n- [ ] GZIP automatically configured to [compress TailwindCSS](https://v1.tailwindcss.com/docs/controlling-file-size) out of the box. \u26a1\n\n## How to add?\n> [!NOTE]\n> These instructions assume you have a somewhat intermediate understanding of FastAPI and that you've used TailwindCSS before (if you haven't be sure to read the documentation I link in tailwind stages) as I may assume some things.\n\n1. Install the pypi package.\n```sh\npip install fastapi-tailwind\n```\n2. Edit your FastAPI APP.\n\nBefore:\n```python\nfrom fastapi import FastAPI\nfrom fastapi.responses import FileResponse\nfrom fastapi.staticfiles import StaticFiles\n\napp = FastAPI()\n\n@app.get(\"/\")\ndef index():\n    return FileResponse(\"./index.html\")\n\napp.mount(\"/static\", StaticFiles(directory = \"static\"), name = \"static\")\n```\n\nAfter:\n```python\n# main.py\n\nfrom fastapi import FastAPI\nfrom fastapi.responses import FileResponse\nfrom fastapi.staticfiles import StaticFiles\n\nfrom fastapi_tailwind import tailwind\nfrom contextlib import asynccontextmanager\n\nstatic_files = StaticFiles(directory = \"static\")\n\n@asynccontextmanager\nasync def lifespan(app: FastAPI):\n    # YAY, our tailwind get's compiled here! \ud83d\ude04\n    process = tailwind.compile(static_files.directory + \"/output.css\")\n\n    yield # The code after this is called on shutdown.\n\n    process.terminate() # We must terminate the compiler on shutdown to\n    # prevent multiple compilers running in development mode or when watch is enabled.\n\napp = FastAPI(\n    # See the fastapi documentation for an explanation on lifespans: https://fastapi.tiangolo.com/advanced/events/\n    lifespan = lifespan\n)\n\n@app.get(\"/\")\ndef index():\n    return FileResponse(\"./index.html\")\n\n# We need somewhere to drop the compiled stylesheet so our html file can link it.\napp.mount(\"/static\", static_files, name = \"static\")\n```\n\n3. Make sure the `static` folder exists.\n```sh\nmkdir ./static\n```\n4. Generate `tailwind.config.js`, then [configure it](https://tailwindcss.com/docs/configuration) appropriately.\n```sh\nfastapi-tailwind-init\n```\n5. Write your tailwind css in `index.html`.\n```html\n<!DOCTYPE html>\n<html lang=\"en\">\n<head>\n    <meta charset=\"UTF-8\">\n    <meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\">\n    <title>\u2728 Tailwind in \ud83d\udd25 FastAPI</title>\n\n    <link rel=\"stylesheet\" href=\"/static/output.css\">\n</head>\n<body class=\"bg-slate-950\">\n    <h1 class=\"mt-10 text-center text-6xl font-bold text-red-400\">\ud83d\udc4b Hello \u2728 Tailwind!</h1>\n</body>\n</html>\n```\n6. Run FastAPI and visit your site.\n```sh\nfastapi dev main.py\n```\n<div align=\"center\">\n\n  <img width=\"800px\" src=\"./assets/example_page_showcase.png\">\n\n</div>\n",
    "bugtrack_url": null,
    "license": "MIT License  Copyright (c) 2024-present Goldy  Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the \"Software\"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:  The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.  THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.",
    "summary": "\u2728 TailwindCSS support for \ud83d\udd25 FastAPI.",
    "version": "1.0.1a7",
    "project_urls": {
        "BugTracker": "https://github.com/THEGOLDENPRO/fastapi-tailwind/issues",
        "GitHub": "https://github.com/THEGOLDENPRO/fastapi-tailwind"
    },
    "split_keywords": [
        "tailwindcss",
        " tailwind",
        " fastapi",
        " fastapi middleware"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "22346e4ad2fb3fa9766be13b73628fad2ac824405267c26bcd6575899ec5b0de",
                "md5": "dc951738d14853e214df7c434e31f1af",
                "sha256": "dc08bd631dd3865c8ac0fa7ff04af8f6bbd20186d89dc9c6bd1487acfcbaa358"
            },
            "downloads": -1,
            "filename": "fastapi_tailwind-1.0.1a7-py3-none-macosx_10_9_arm64.whl",
            "has_sig": false,
            "md5_digest": "dc951738d14853e214df7c434e31f1af",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.8",
            "size": 19311787,
            "upload_time": "2024-09-04T20:40:30",
            "upload_time_iso_8601": "2024-09-04T20:40:30.452947Z",
            "url": "https://files.pythonhosted.org/packages/22/34/6e4ad2fb3fa9766be13b73628fad2ac824405267c26bcd6575899ec5b0de/fastapi_tailwind-1.0.1a7-py3-none-macosx_10_9_arm64.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "7fb1373dbc7df8363d771373f78d9ef73bd814a74dfce82a1aa3a1ea212c4dc0",
                "md5": "57fe6311ea88a0a4455186d0853020f9",
                "sha256": "07aba3110e319c77e618c275deaf365764f52818de01be1949d86447c379c9af"
            },
            "downloads": -1,
            "filename": "fastapi_tailwind-1.0.1a7-py3-none-macosx_10_9_x86_64.whl",
            "has_sig": false,
            "md5_digest": "57fe6311ea88a0a4455186d0853020f9",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.8",
            "size": 20892055,
            "upload_time": "2024-09-04T20:40:41",
            "upload_time_iso_8601": "2024-09-04T20:40:41.826304Z",
            "url": "https://files.pythonhosted.org/packages/7f/b1/373dbc7df8363d771373f78d9ef73bd814a74dfce82a1aa3a1ea212c4dc0/fastapi_tailwind-1.0.1a7-py3-none-macosx_10_9_x86_64.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "7dc4fabf04a0650452903b50ec25302435538ff1510a6102cc42fe13875f7895",
                "md5": "2a06e05423eb4f11007c2e45a9d8b4b0",
                "sha256": "1b6755ebe17dd51375bb67db9c9bd3a8d84dc18f1b195677a120f9ef530f107f"
            },
            "downloads": -1,
            "filename": "fastapi_tailwind-1.0.1a7-py3-none-manylinux2014_aarch64.whl",
            "has_sig": false,
            "md5_digest": "2a06e05423eb4f11007c2e45a9d8b4b0",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.8",
            "size": 18184680,
            "upload_time": "2024-09-04T20:40:52",
            "upload_time_iso_8601": "2024-09-04T20:40:52.471822Z",
            "url": "https://files.pythonhosted.org/packages/7d/c4/fabf04a0650452903b50ec25302435538ff1510a6102cc42fe13875f7895/fastapi_tailwind-1.0.1a7-py3-none-manylinux2014_aarch64.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "17708e588261c44db5ec2c50c4c68466c47e1422347f03b5abe8d1741e471dbf",
                "md5": "092478736d166eda9537627197f8ba6e",
                "sha256": "ee3591a0dbad7d21827a575e9f40d89de78eb6c67b67c97334e5289e0f6a412d"
            },
            "downloads": -1,
            "filename": "fastapi_tailwind-1.0.1a7-py3-none-manylinux2014_armv7l.whl",
            "has_sig": false,
            "md5_digest": "092478736d166eda9537627197f8ba6e",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.8",
            "size": 17487909,
            "upload_time": "2024-09-04T20:41:02",
            "upload_time_iso_8601": "2024-09-04T20:41:02.715217Z",
            "url": "https://files.pythonhosted.org/packages/17/70/8e588261c44db5ec2c50c4c68466c47e1422347f03b5abe8d1741e471dbf/fastapi_tailwind-1.0.1a7-py3-none-manylinux2014_armv7l.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "e8eeeb39801053b852601e25ecdb2f4d20e8596fbd415d1bc233dfe737390e5c",
                "md5": "295e5e4e2e5888e3312896358f4c5832",
                "sha256": "054e189882f3f18b5c3d75c3de3ed46ebd836ed159614a43cbba2a98b3629ed7"
            },
            "downloads": -1,
            "filename": "fastapi_tailwind-1.0.1a7-py3-none-manylinux2014_x86_64.whl",
            "has_sig": false,
            "md5_digest": "295e5e4e2e5888e3312896358f4c5832",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.8",
            "size": 18500487,
            "upload_time": "2024-09-04T20:41:13",
            "upload_time_iso_8601": "2024-09-04T20:41:13.104401Z",
            "url": "https://files.pythonhosted.org/packages/e8/ee/eb39801053b852601e25ecdb2f4d20e8596fbd415d1bc233dfe737390e5c/fastapi_tailwind-1.0.1a7-py3-none-manylinux2014_x86_64.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "3febeaaed976db22a8534b6db2fa1869e006f5a96f91f21ec6facf2c3a3bb7e7",
                "md5": "30393e536954633aaf54896941519d1f",
                "sha256": "491fc6cd1ce26e6d9145c594e13385ee46c66db96d2c5213b47f4b956bb2a1b1"
            },
            "downloads": -1,
            "filename": "fastapi_tailwind-1.0.1a7-py3-none-musllinux_1_2_aarch64.whl",
            "has_sig": false,
            "md5_digest": "30393e536954633aaf54896941519d1f",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.8",
            "size": 18184849,
            "upload_time": "2024-09-04T20:41:23",
            "upload_time_iso_8601": "2024-09-04T20:41:23.664755Z",
            "url": "https://files.pythonhosted.org/packages/3f/eb/eaaed976db22a8534b6db2fa1869e006f5a96f91f21ec6facf2c3a3bb7e7/fastapi_tailwind-1.0.1a7-py3-none-musllinux_1_2_aarch64.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "04db7f4b17d019062677fc9c95f2b7a047beb14436d0ba780631b0bd03e6ff81",
                "md5": "fd3f8dac59263399598971f1b5892df5",
                "sha256": "c9de4ca00e5ffb3cb5ad3573999da411fec4aeac0c53b4849fdb9e68740b96e3"
            },
            "downloads": -1,
            "filename": "fastapi_tailwind-1.0.1a7-py3-none-musllinux_1_2_armv7l.whl",
            "has_sig": false,
            "md5_digest": "fd3f8dac59263399598971f1b5892df5",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.8",
            "size": 17488077,
            "upload_time": "2024-09-04T20:41:36",
            "upload_time_iso_8601": "2024-09-04T20:41:36.346886Z",
            "url": "https://files.pythonhosted.org/packages/04/db/7f4b17d019062677fc9c95f2b7a047beb14436d0ba780631b0bd03e6ff81/fastapi_tailwind-1.0.1a7-py3-none-musllinux_1_2_armv7l.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "3894e552f35e7b228efeec205a860a4ddc18684c406fbc4d5d95a3703199a74e",
                "md5": "53ef97ea686e3556bfc3c6aeb7417048",
                "sha256": "9a49c5ef52e0359c6ab3a615dd9665b9046f72cc1ba723af37d2331d523f81d0"
            },
            "downloads": -1,
            "filename": "fastapi_tailwind-1.0.1a7-py3-none-musllinux_1_2_x86_64.whl",
            "has_sig": false,
            "md5_digest": "53ef97ea686e3556bfc3c6aeb7417048",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.8",
            "size": 18500655,
            "upload_time": "2024-09-04T20:41:46",
            "upload_time_iso_8601": "2024-09-04T20:41:46.445134Z",
            "url": "https://files.pythonhosted.org/packages/38/94/e552f35e7b228efeec205a860a4ddc18684c406fbc4d5d95a3703199a74e/fastapi_tailwind-1.0.1a7-py3-none-musllinux_1_2_x86_64.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "54ef5219642cf78956ee5e2ffc923ee5781c868a8fb30b55a9a24d5cdc8bc6e5",
                "md5": "1974d9c188634c1a6b7968f6f40323d1",
                "sha256": "7055220a2391be5124de373c2f5cda3a6885086c54bee6176ece0f7d6bace25c"
            },
            "downloads": -1,
            "filename": "fastapi_tailwind-1.0.1a7-py3-none-win_amd64.whl",
            "has_sig": false,
            "md5_digest": "1974d9c188634c1a6b7968f6f40323d1",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.8",
            "size": 17304666,
            "upload_time": "2024-09-04T20:41:55",
            "upload_time_iso_8601": "2024-09-04T20:41:55.974909Z",
            "url": "https://files.pythonhosted.org/packages/54/ef/5219642cf78956ee5e2ffc923ee5781c868a8fb30b55a9a24d5cdc8bc6e5/fastapi_tailwind-1.0.1a7-py3-none-win_amd64.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "b856ff231626d2c5d794aa4045041ce905109485b4f2f40806cedcb2ad2246e2",
                "md5": "3935416281f08f08f6200c3b74a1429f",
                "sha256": "ea4aa223affdec3672c02c211c55a9088865fe30fa8be166e28918990e5ea503"
            },
            "downloads": -1,
            "filename": "fastapi_tailwind-1.0.1a7-py3-none-win_arm64.whl",
            "has_sig": false,
            "md5_digest": "3935416281f08f08f6200c3b74a1429f",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.8",
            "size": 12561824,
            "upload_time": "2024-09-04T20:42:03",
            "upload_time_iso_8601": "2024-09-04T20:42:03.497733Z",
            "url": "https://files.pythonhosted.org/packages/b8/56/ff231626d2c5d794aa4045041ce905109485b4f2f40806cedcb2ad2246e2/fastapi_tailwind-1.0.1a7-py3-none-win_arm64.whl",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-09-04 20:40:30",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "THEGOLDENPRO",
    "github_project": "fastapi-tailwind",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "lcname": "fastapi-tailwind"
}
        
Elapsed time: 4.68026s