flask-livetw


Nameflask-livetw JSON
Version 0.4.2 PyPI version JSON
download
home_pageNone
SummaryA simple package that enables live reload and Tailwind CSS for Flask templates.
upload_time2024-03-23 23:17:17
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 server separately 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/27/ee/72915e72fe87c9025a5268548276332a7541b2857b2d16f284c98ad8d064/flask-livetw-0.4.2.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 server separately 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.2",
    "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": "343d9c62e5d33d8a5f28ad0c489e852728f9f5a6b680c02fee7606dea02d0ef9",
                "md5": "840523b05795178e1ee092933662d74a",
                "sha256": "1924217175aacf082fa45fec1d559242d3e3a31c493fe990092b9b163eb69cd2"
            },
            "downloads": -1,
            "filename": "flask_livetw-0.4.2-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "840523b05795178e1ee092933662d74a",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.8",
            "size": 19045,
            "upload_time": "2024-03-23T23:17:15",
            "upload_time_iso_8601": "2024-03-23T23:17:15.119632Z",
            "url": "https://files.pythonhosted.org/packages/34/3d/9c62e5d33d8a5f28ad0c489e852728f9f5a6b680c02fee7606dea02d0ef9/flask_livetw-0.4.2-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "27ee72915e72fe87c9025a5268548276332a7541b2857b2d16f284c98ad8d064",
                "md5": "570370f8987502a174360eff26aa06d3",
                "sha256": "069e293d82ecba6afa83975cc537dda12021dbb1463a3943a5b7342474147646"
            },
            "downloads": -1,
            "filename": "flask-livetw-0.4.2.tar.gz",
            "has_sig": false,
            "md5_digest": "570370f8987502a174360eff26aa06d3",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.8",
            "size": 17608,
            "upload_time": "2024-03-23T23:17:17",
            "upload_time_iso_8601": "2024-03-23T23:17:17.011487Z",
            "url": "https://files.pythonhosted.org/packages/27/ee/72915e72fe87c9025a5268548276332a7541b2857b2d16f284c98ad8d064/flask-livetw-0.4.2.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-03-23 23:17:17",
    "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": [
                [
                    ">=",
                    "11"
                ]
            ]
        },
        {
            "name": "tomli",
            "specs": [
                [
                    ">=",
                    "2"
                ]
            ]
        }
    ],
    "lcname": "flask-livetw"
}
        
Elapsed time: 0.20523s