flask-livetw


Nameflask-livetw JSON
Version 0.4.3 PyPI version JSON
download
home_pageNone
SummaryA simple package that enables live reload and Tailwind CSS for Flask templates.
upload_time2024-09-23 16:19:16
maintainerNone
docs_urlNone
authorNone
requires_python>=3.8
licenseMIT License Copyright (c) 2023 Josue 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 flask tailwindcss livereload css html template
VCS
bugtrack_url
requirements pytailwindcss websockets tomli
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # Flask live tailwindcss

A simple package for adding a dev server to your flask app that automatically compiles the tailwindcss of the templates on file save and triggers a browser reload to sync the changes on the fly.


## Installation

This package is available on PyPI, you can install it using `pip` or other package manager of your choice.

```bash
pip install flask-livetw
```

Its a good practice to add as a development dependency. You can do this by adding the package to your `requirements-dev.txt` file or the "dev dependencies" of your package manager.

```txt
flask-livetw
```


## Initialization

To start using this package, go to your project folder or the folder where you want to develop. Then run the following command to initialize the package.

```bash
livetw init
```

> For default values use the `-d` or `--default` flag.

Then where you have your flask app add the following configuration to enable the live reload feature.

```py
import os

...

app.config["LIVETW_DEV"] = os.getenv("LIVETW_ENV") == "development"
```

When running the flask without `livetw dev` during development remember to set the `LIVETW_DEV` to `True` in your flask app configuration to enable the live reload feature.

```py
app.config["LIVETW_DEV"] = True
```

For more information on the configuration options see the [Configuration](#configuration) section.


## Commands

Each command has its own help page, you can use the `-h` or `--help` flag to see the available options.

### dev

```bash
livetw dev
```

By default the command starts:

- a flask server in debug mode
- a live reload websocket server
- a tailwindcss in watch mode

This command sets the enviroment variable `LIVETW_ENV` to `development`. This is useful for conditional code execution.

### build

Builds the Tailwind CSS for the templates into a single CSS file.

```bash
livetw build
```

By default, the built Tailwind CSS file will be minified to reduce the file size. You can disable this feature by using the `--no-minify` flag.

```bash
livetw build --no-minify
```

### init

Initializes the package in the current directory. Its the command used in [Initialization](#initialization).

```bash
livetw init
```


## Configuration

After initialization, a `pyproject.toml` file will be created if it does not exist. In this file under the `[tool.flask-livetw]` section

This is an example of a configuration file with the default values:

```toml
[tool.flask-livetw]
flask_root = "src"
static_folder = "static"
template_folder = "templates"
template_glob = "**/*.html"
base_layout = "layout.html"
livetw_folder = ".dev"
flask_app = "app"
```

As a file tree, the configuration would look like this:

```txt
🌳 project_folder/
┣ 📁 src/
┃ ┣ 📁 static/
┃ ┃ ┣ 📁 .dev/
┃ ┃ ┗ ...
┃ ┣ 📁 templates/
┃ ┃ ┣ 📄 layout.html
┃ ┃ ┗ ...
┃ ┗ ...
┃ 📄 app.py
┣ 📄 pyproject.toml
┗ ...
```

### Main options

#### flask_root

The root folder of the flask application. All paths are relative to this folder.

Default is `"src"`.

#### flask_app

The argument `--app` passed to flask to discover the application. For more information see the [Flask Application Discovery](https://flask.palletsprojects.com/en/3.0.x/cli/) documentation.

Default is `"app"`.

#### static_folder

The folder where the static files are stored relative to the `flask_root`.

Default is `"static"`.

#### template_folder

The folder where the templates are stored relative to the `flask_root`.

Default is `"templates"`.

#### template_glob

The glob pattern to search for templates to build the Tailwind CSS. Must be relative to the `template_folder`.

Default is `"**/*.html"`.

For more information see the [Tailwindcss configuring source paths](https://tailwindcss.com/docs/content-configuration) documentation.

#### base_layout

The layout that is shared among all templates. This file is used to inject the Tailwind CSS and the live reload script. If it isn't shared among all templates, the Tailwind CSS and the live reload script won't be injected into the templates.

Default is `"layout.html"`.

#### livetw_folder

The folder where flask-livetw stores the related files.

It contains:

- `global.css`: The global CSS file for the application.
- `live_reload.js`: The live reload script for the application.
- `tailwind_development.css`: The Tailwind CSS file for the application during development.

Default is `".dev"`.

### Other options

#### global_css

The global CSS file for the application relative to the `livetw_folder`.

Default is `"global.css"`.

#### tailwind_prod

The production CSS file for the application relative to the `static_folder`.

Default is `"tailwind_production.css"`.

#### live_reload_host

The host for websocket server for the live reload functionality. If set must be manually sync on the live reload script for the client.

Default is `"127.0.0.1"`.

#### live_reload_port

The port for websocket server for the live reload functionality. If set must be manually sync on the live reload script for the client.

Default is `5678`.

#### flask_host

The host for the Flask application.

Default is `"127.0.0.1"`.

#### flask_port

The port for the Flask application.

Default is `5000`.

#### flask_exclude_patterns

The patterns to exclude python scripts from the Flask application. This is useful to exclude files from triggering the flask server to reload.


## Contributing

Contributions are welcome, feel free to submit a pull request or an issue.


## Packages used

- [pytailwindcss](https://github.com/timonweb/pytailwindcss)
- [tomli](https://github.com/hukkin/tomli)
- [websockets](https://github.com/python-websockets/websockets)


## License

[MIT](./LICENSE)

            

Raw data

            {
    "_id": null,
    "home_page": null,
    "name": "flask-livetw",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.8",
    "maintainer_email": null,
    "keywords": "flask, tailwindcss, livereload, css, html, template",
    "author": null,
    "author_email": "Josue <josue.sa.trabajos@gmail.com>",
    "download_url": "https://files.pythonhosted.org/packages/06/d9/aed06bcc5ac6442a106a28c5119869e254607713f035b2907bbeef8bc01c/flask_livetw-0.4.3.tar.gz",
    "platform": null,
    "description": "# Flask live tailwindcss\r\n\r\nA simple package for adding a dev server to your flask app that automatically compiles the tailwindcss of the templates on file save and triggers a browser reload to sync the changes on the fly.\r\n\r\n\r\n## Installation\r\n\r\nThis package is available on PyPI, you can install it using `pip` or other package manager of your choice.\r\n\r\n```bash\r\npip install flask-livetw\r\n```\r\n\r\nIts a good practice to add as a development dependency. You can do this by adding the package to your `requirements-dev.txt` file or the \"dev dependencies\" of your package manager.\r\n\r\n```txt\r\nflask-livetw\r\n```\r\n\r\n\r\n## Initialization\r\n\r\nTo start using this package, go to your project folder or the folder where you want to develop. Then run the following command to initialize the package.\r\n\r\n```bash\r\nlivetw init\r\n```\r\n\r\n> For default values use the `-d` or `--default` flag.\r\n\r\nThen where you have your flask app add the following configuration to enable the live reload feature.\r\n\r\n```py\r\nimport os\r\n\r\n...\r\n\r\napp.config[\"LIVETW_DEV\"] = os.getenv(\"LIVETW_ENV\") == \"development\"\r\n```\r\n\r\nWhen running the flask without `livetw dev` during development remember to set the `LIVETW_DEV` to `True` in your flask app configuration to enable the live reload feature.\r\n\r\n```py\r\napp.config[\"LIVETW_DEV\"] = True\r\n```\r\n\r\nFor more information on the configuration options see the [Configuration](#configuration) section.\r\n\r\n\r\n## Commands\r\n\r\nEach command has its own help page, you can use the `-h` or `--help` flag to see the available options.\r\n\r\n### dev\r\n\r\n```bash\r\nlivetw dev\r\n```\r\n\r\nBy default the command starts:\r\n\r\n- a flask server in debug mode\r\n- a live reload websocket server\r\n- a tailwindcss in watch mode\r\n\r\nThis command sets the enviroment variable `LIVETW_ENV` to `development`. This is useful for conditional code execution.\r\n\r\n### build\r\n\r\nBuilds the Tailwind CSS for the templates into a single CSS file.\r\n\r\n```bash\r\nlivetw build\r\n```\r\n\r\nBy default, the built Tailwind CSS file will be minified to reduce the file size. You can disable this feature by using the `--no-minify` flag.\r\n\r\n```bash\r\nlivetw build --no-minify\r\n```\r\n\r\n### init\r\n\r\nInitializes the package in the current directory. Its the command used in [Initialization](#initialization).\r\n\r\n```bash\r\nlivetw init\r\n```\r\n\r\n\r\n## Configuration\r\n\r\nAfter initialization, a `pyproject.toml` file will be created if it does not exist. In this file under the `[tool.flask-livetw]` section\r\n\r\nThis is an example of a configuration file with the default values:\r\n\r\n```toml\r\n[tool.flask-livetw]\r\nflask_root = \"src\"\r\nstatic_folder = \"static\"\r\ntemplate_folder = \"templates\"\r\ntemplate_glob = \"**/*.html\"\r\nbase_layout = \"layout.html\"\r\nlivetw_folder = \".dev\"\r\nflask_app = \"app\"\r\n```\r\n\r\nAs a file tree, the configuration would look like this:\r\n\r\n```txt\r\n\ud83c\udf33 project_folder/\r\n\u2523 \ud83d\udcc1 src/\r\n\u2503 \u2523 \ud83d\udcc1 static/\r\n\u2503 \u2503 \u2523 \ud83d\udcc1 .dev/\r\n\u2503 \u2503 \u2517 ...\r\n\u2503 \u2523 \ud83d\udcc1 templates/\r\n\u2503 \u2503 \u2523 \ud83d\udcc4 layout.html\r\n\u2503 \u2503 \u2517 ...\r\n\u2503 \u2517 ...\r\n\u2503 \ud83d\udcc4 app.py\r\n\u2523 \ud83d\udcc4 pyproject.toml\r\n\u2517 ...\r\n```\r\n\r\n### Main options\r\n\r\n#### flask_root\r\n\r\nThe root folder of the flask application. All paths are relative to this folder.\r\n\r\nDefault is `\"src\"`.\r\n\r\n#### flask_app\r\n\r\nThe argument `--app` passed to flask to discover the application. For more information see the [Flask Application Discovery](https://flask.palletsprojects.com/en/3.0.x/cli/) documentation.\r\n\r\nDefault is `\"app\"`.\r\n\r\n#### static_folder\r\n\r\nThe folder where the static files are stored relative to the `flask_root`.\r\n\r\nDefault is `\"static\"`.\r\n\r\n#### template_folder\r\n\r\nThe folder where the templates are stored relative to the `flask_root`.\r\n\r\nDefault is `\"templates\"`.\r\n\r\n#### template_glob\r\n\r\nThe glob pattern to search for templates to build the Tailwind CSS. Must be relative to the `template_folder`.\r\n\r\nDefault is `\"**/*.html\"`.\r\n\r\nFor more information see the [Tailwindcss configuring source paths](https://tailwindcss.com/docs/content-configuration) documentation.\r\n\r\n#### base_layout\r\n\r\nThe layout that is shared among all templates. This file is used to inject the Tailwind CSS and the live reload script. If it isn't shared among all templates, the Tailwind CSS and the live reload script won't be injected into the templates.\r\n\r\nDefault is `\"layout.html\"`.\r\n\r\n#### livetw_folder\r\n\r\nThe folder where flask-livetw stores the related files.\r\n\r\nIt contains:\r\n\r\n- `global.css`: The global CSS file for the application.\r\n- `live_reload.js`: The live reload script for the application.\r\n- `tailwind_development.css`: The Tailwind CSS file for the application during development.\r\n\r\nDefault is `\".dev\"`.\r\n\r\n### Other options\r\n\r\n#### global_css\r\n\r\nThe global CSS file for the application relative to the `livetw_folder`.\r\n\r\nDefault is `\"global.css\"`.\r\n\r\n#### tailwind_prod\r\n\r\nThe production CSS file for the application relative to the `static_folder`.\r\n\r\nDefault is `\"tailwind_production.css\"`.\r\n\r\n#### live_reload_host\r\n\r\nThe host for websocket server for the live reload functionality. If set must be manually sync on the live reload script for the client.\r\n\r\nDefault is `\"127.0.0.1\"`.\r\n\r\n#### live_reload_port\r\n\r\nThe port for websocket server for the live reload functionality. If set must be manually sync on the live reload script for the client.\r\n\r\nDefault is `5678`.\r\n\r\n#### flask_host\r\n\r\nThe host for the Flask application.\r\n\r\nDefault is `\"127.0.0.1\"`.\r\n\r\n#### flask_port\r\n\r\nThe port for the Flask application.\r\n\r\nDefault is `5000`.\r\n\r\n#### flask_exclude_patterns\r\n\r\nThe patterns to exclude python scripts from the Flask application. This is useful to exclude files from triggering the flask server to reload.\r\n\r\n\r\n## Contributing\r\n\r\nContributions are welcome, feel free to submit a pull request or an issue.\r\n\r\n\r\n## Packages used\r\n\r\n- [pytailwindcss](https://github.com/timonweb/pytailwindcss)\r\n- [tomli](https://github.com/hukkin/tomli)\r\n- [websockets](https://github.com/python-websockets/websockets)\r\n\r\n\r\n## License\r\n\r\n[MIT](./LICENSE)\r\n",
    "bugtrack_url": null,
    "license": "MIT License  Copyright (c) 2023 Josue  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": "A simple package that enables live reload and Tailwind CSS for Flask templates.",
    "version": "0.4.3",
    "project_urls": {
        "issues": "https://github.com/josu-dev/flask-livetw/issues",
        "repository": "https://github.com/josu-dev/flask-livetw.git"
    },
    "split_keywords": [
        "flask",
        " tailwindcss",
        " livereload",
        " css",
        " html",
        " template"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "f64e48ef9b39ea49d19b22ca5e1847048a933600a157a299dd23ec5b2c8023f6",
                "md5": "523438a87f6f86a45fd7de28506ff854",
                "sha256": "9277c1a456949fac782446a463ee131f0b36a9e07b29a0fa27df2b9b570a1504"
            },
            "downloads": -1,
            "filename": "flask_livetw-0.4.3-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "523438a87f6f86a45fd7de28506ff854",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.8",
            "size": 19259,
            "upload_time": "2024-09-23T16:19:14",
            "upload_time_iso_8601": "2024-09-23T16:19:14.409131Z",
            "url": "https://files.pythonhosted.org/packages/f6/4e/48ef9b39ea49d19b22ca5e1847048a933600a157a299dd23ec5b2c8023f6/flask_livetw-0.4.3-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "06d9aed06bcc5ac6442a106a28c5119869e254607713f035b2907bbeef8bc01c",
                "md5": "d81f3a0404785da66f890586de99ee16",
                "sha256": "f9642837dbf4eeadf43f665b634134dbc3be250a53ac1961a9d5cc9efaacd021"
            },
            "downloads": -1,
            "filename": "flask_livetw-0.4.3.tar.gz",
            "has_sig": false,
            "md5_digest": "d81f3a0404785da66f890586de99ee16",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.8",
            "size": 17960,
            "upload_time": "2024-09-23T16:19:16",
            "upload_time_iso_8601": "2024-09-23T16:19:16.260875Z",
            "url": "https://files.pythonhosted.org/packages/06/d9/aed06bcc5ac6442a106a28c5119869e254607713f035b2907bbeef8bc01c/flask_livetw-0.4.3.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-09-23 16:19:16",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "josu-dev",
    "github_project": "flask-livetw",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "requirements": [
        {
            "name": "pytailwindcss",
            "specs": [
                [
                    ">=",
                    "0.2"
                ]
            ]
        },
        {
            "name": "websockets",
            "specs": [
                [
                    ">=",
                    "13.1"
                ]
            ]
        },
        {
            "name": "tomli",
            "specs": [
                [
                    ">=",
                    "2"
                ]
            ]
        }
    ],
    "lcname": "flask-livetw"
}
        
Elapsed time: 9.11697s