Registry / devops / pytailwindcss

pytailwindcss

JSON →
library0.3.1pypypi✓ verified 85d ago

pytailwindcss provides a Python-installable wrapper for the standalone Tailwind CSS CLI, enabling developers to use Tailwind CSS in Python projects without requiring Node.js. It bundles a specific version of the Tailwind CLI executable. The current version is 0.3.0, and releases are tied to updates of the underlying Tailwind CSS CLI or Python API improvements.

pip install pytailwindcss
INSTALL
IMPORT
SIG · PYTAILWINDCSS
P
pytailwindcss
devopspythonv0.3.1
Install
1.5s avg
Import
Disk
16MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v0.2.0 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.910 runs
installs and imports cleanly · install 0.0s · import 0.000s · 17.8MB
glibc
py 3.103.910 runs
installs and imports cleanly · install 1.5s · import 0.000s · 18MB
16MB installed
● package 16MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

run
from pytailwindcss import run
from pytailwindcss import run_tailwind_cli
install
from pytailwindcss import install
PyTailwindCssBinaryNotFound
from pytailwindcss import PyTailwindCssBinaryNotFound

This quickstart demonstrates how to use `run_tailwind_cli` to compile CSS. It creates a temporary directory with a `tailwind.config.js`, `input.css`, and a dummy HTML file, runs the build process, prints a snippet of the output, and then cleans up all temporary files. Ensure you have `tailwind.config.js` and `input.css` in your project for real use.

import os from pathlib import Path from pytailwindcss import run_tailwind_cli import sys # Define a temporary directory for the quickstart example temp_dir = Path("pytailwindcss_quickstart_temp") temp_dir.mkdir(exist_ok=True) # Create dummy files for the quickstart to be runnable config_path = temp_dir / "tailwind.config.js" input_css_path = temp_dir / "input.css" output_css_path = temp_dir / "output.css" templates_dir = temp_dir / "templates" templates_dir.mkdir(exist_ok=True) html_path = templates_dir / "index.html" # Write dummy config config_path.write_text(""" module.exports = { content: ['./templates/*.html'], theme: { extend: {}, }, plugins: [], } """) # Write dummy input CSS input_css_path.write_text(""" @tailwind base; @tailwind components; @tailwind utilities; h1 { @apply text-blue-600; } """) # Write dummy HTML html_path.write_text(""" <!DOCTYPE html> <html> <head> <link href="output.css" rel="stylesheet"> </head> <body> <h1 class="text-xl font-bold">Hello Tailwind</h1> </body> </html> """) original_cwd = Path.cwd() os.chdir(temp_dir) # Change CWD for the CLI to find files relative to temp_dir print(f"Running Tailwind CSS build in {temp_dir}...") try: # Example arguments for a basic build # Using relative paths because we changed CWD result = run_tailwind_cli([ '-i', 'input.css', '-o', 'output.css', '--minify' ]) if result.returncode == 0: print("Tailwind CSS build successful!") if output_css_path.exists(): print("\nGenerated output.css (first 200 chars):\n") print(output_css_path.read_text()[:200]) else: print("output.css not found, but build reported success.") else: print(f"Tailwind CSS build failed with return code {result.returncode}.") if result.stdout: print(f"Stdout:\n{result.stdout.decode(sys.getdefaultencoding())}") if result.stderr: print(f"Stderr:\n{result.stderr.decode(sys.getdefaultencoding())}") except Exception as e: print(f"An unexpected error occurred: {e}") finally: os.chdir(original_cwd) # Restore original CWD # Clean up dummy files print(f"\nCleaning up temporary files in {temp_dir}...") for f in temp_dir.iterdir(): if f.is_file(): f.unlink() elif f.is_dir(): for sub_f in f.iterdir(): sub_f.unlink() f.rmdir() temp_dir.rmdir() print("Cleanup complete.")
tailwindcss --version
Debug
Known issues
gotchaThe `pytailwindcss` package bundles a specific version of the standalone Tailwind CSS CLI. To update the Tailwind CSS CLI version (e.g., to get new features or bug fixes from Tailwind CSS itself), you must update the `pytailwindcss` Python package itself.
fix
Run `pip install --upgrade pytailwindcss` to get the latest bundled CLI version.
affects: All versions
gotchaWhen using `run_tailwind_cli`, ensure that input (`-i`) and output (`-o`) CSS paths, as well as the `content` paths in your `tailwind.config.js`, are correctly resolved. These paths are relative to the current working directory of the Python script or absolute paths.
fix
Use `pathlib.Path.cwd()` and `os.chdir()` or provide absolute paths to `run_tailwind_cli` for consistency, especially in complex project structures.
affects: All versions
gotchaThe `run_tailwind_cli` function expects a list of strings for CLI arguments (e.g., `['-i', 'input.css', '--minify']`), not a single string that would be parsed by a shell. Passing arguments as a single string will lead to incorrect parsing.
fix
Always pass CLI arguments as a list of individual strings, mirroring how you would type them in a shell (e.g., `['build', '-i', 'src.css', '-o', 'dist.css']`).
affects: All versions
Upgrade
Version history
0.3.1latest on PyPI · released Jun 12, 2026
Audit
Dependencies

No dependency data recorded yet.

Agent activity
7 hits · last 30 days
node
6
Resources
pytailwindcss — pip install pytailwindcss · libregistry