{"id":10136,"library":"pytailwindcss","title":"pytailwindcss","description":"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.","status":"active","version":"0.3.0","language":"en","source_language":"en","source_url":"https://github.com/timonweb/pytailwindcss","tags":["tailwindcss","css","build-tool","cli","frontend"],"install":[{"cmd":"pip install pytailwindcss","lang":"bash","label":"Install stable version"}],"dependencies":[],"imports":[{"note":"This is the primary function to invoke the Tailwind CSS CLI.","symbol":"run_tailwind_cli","correct":"from pytailwindcss import run_tailwind_cli"}],"quickstart":{"code":"import os\nfrom pathlib import Path\nfrom pytailwindcss import run_tailwind_cli\nimport sys\n\n# Define a temporary directory for the quickstart example\ntemp_dir = Path(\"pytailwindcss_quickstart_temp\")\ntemp_dir.mkdir(exist_ok=True)\n\n# Create dummy files for the quickstart to be runnable\nconfig_path = temp_dir / \"tailwind.config.js\"\ninput_css_path = temp_dir / \"input.css\"\noutput_css_path = temp_dir / \"output.css\"\ntemplates_dir = temp_dir / \"templates\"\ntemplates_dir.mkdir(exist_ok=True)\nhtml_path = templates_dir / \"index.html\"\n\n# Write dummy config\nconfig_path.write_text(\"\"\"\nmodule.exports = {\n  content: ['./templates/*.html'],\n  theme: {\n    extend: {},\n  },\n  plugins: [],\n}\n\"\"\")\n\n# Write dummy input CSS\ninput_css_path.write_text(\"\"\"\n@tailwind base;\n@tailwind components;\n@tailwind utilities;\n\nh1 { @apply text-blue-600; }\n\"\"\")\n\n# Write dummy HTML\nhtml_path.write_text(\"\"\"\n<!DOCTYPE html>\n<html>\n<head>\n  <link href=\"output.css\" rel=\"stylesheet\">\n</head>\n<body>\n  <h1 class=\"text-xl font-bold\">Hello Tailwind</h1>\n</body>\n</html>\n\"\"\")\n\noriginal_cwd = Path.cwd()\nos.chdir(temp_dir) # Change CWD for the CLI to find files relative to temp_dir\n\nprint(f\"Running Tailwind CSS build in {temp_dir}...\")\ntry:\n    # Example arguments for a basic build\n    # Using relative paths because we changed CWD\n    result = run_tailwind_cli([\n        '-i', 'input.css',\n        '-o', 'output.css',\n        '--minify'\n    ])\n\n    if result.returncode == 0:\n        print(\"Tailwind CSS build successful!\")\n        if output_css_path.exists():\n            print(\"\\nGenerated output.css (first 200 chars):\\n\")\n            print(output_css_path.read_text()[:200])\n        else:\n            print(\"output.css not found, but build reported success.\")\n    else:\n        print(f\"Tailwind CSS build failed with return code {result.returncode}.\")\n        if result.stdout:\n            print(f\"Stdout:\\n{result.stdout.decode(sys.getdefaultencoding())}\")\n        if result.stderr:\n            print(f\"Stderr:\\n{result.stderr.decode(sys.getdefaultencoding())}\")\n\nexcept Exception as e:\n    print(f\"An unexpected error occurred: {e}\")\nfinally:\n    os.chdir(original_cwd) # Restore original CWD\n    # Clean up dummy files\n    print(f\"\\nCleaning up temporary files in {temp_dir}...\")\n    for f in temp_dir.iterdir():\n        if f.is_file():\n            f.unlink()\n        elif f.is_dir():\n            for sub_f in f.iterdir():\n                sub_f.unlink()\n            f.rmdir()\n    temp_dir.rmdir()\n    print(\"Cleanup complete.\")\n","lang":"python","description":"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."},"warnings":[{"fix":"Run `pip install --upgrade pytailwindcss` to get the latest bundled CLI version.","message":"The `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.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Use `pathlib.Path.cwd()` and `os.chdir()` or provide absolute paths to `run_tailwind_cli` for consistency, especially in complex project structures.","message":"When 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.","severity":"gotcha","affected_versions":"All versions"},{"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']`).","message":"The `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.","severity":"gotcha","affected_versions":"All versions"}],"env_vars":null,"last_verified":"2026-04-17T00:00:00.000Z","next_check":"2026-07-16T00:00:00.000Z","problems":[{"fix":"Run `pip install pytailwindcss`.","cause":"The `pytailwindcss` package has not been installed in your current Python environment.","error":"ModuleNotFoundError: No module named 'pytailwindcss'"},{"fix":"Use the Python API: `from pytailwindcss import run_tailwind_cli` and call it as a function within your Python script.","cause":"You are attempting to run the `tailwind` command directly from your system shell. `pytailwindcss` provides a Python API (`run_tailwind_cli`), but does not install a global `tailwind` executable to your system's PATH.","error":"FileNotFoundError: [Errno 2] No such file or directory: 'tailwind'"},{"fix":"Examine the `stdout` and `stderr` output from the `run_tailwind_cli` result object for specific error messages from the Tailwind CLI. Verify your `tailwind.config.js` and input CSS files are correctly configured and accessible.","cause":"The underlying Tailwind CSS CLI command failed. This often indicates issues with the input CSS path (`-i`), output CSS path (`-o`), the `tailwind.config.js` configuration (e.g., incorrect `content` paths), or syntax errors in your CSS.","error":"Tailwind CSS build failed with return code X"}]}