This is pkg to load styling (tailwindcss and bootstrap) for reactpy, backend reactpy or other html files
Project description
ReactFlow CSS
ReactFlow CSS is a Python package that simplifies the integration of popular CSS frameworks like Tailwind CSS and Bootstrap into your ReactPy applications and other HTML projects. It provides a streamlined API for configuring, compiling, and serving CSS, making it easier to manage your styling directly from Python.
Features
- Tailwind CSS Integration: Configure and compile Tailwind CSS seamlessly within your Python project
- Bootstrap Integration: Include Bootstrap CSS and JavaScript with minimal setup
- ReactPy Compatibility: Designed specifically for ReactPy components and workflows
- Unified API: A
Helperclass to manage both frameworks through a single interface - Template Management: Built-in templates and default styles for rapid development
Installation
Install ReactFlow CSS using pip:
pip install ReactFlow-CSS
Quick Start
Basic Configuration
First, create configurations for your preferred CSS framework:
# For Tailwind CSS
from reactflow_css.tailwindcss import configure_tailwind
config_tailwind = configure_tailwind(__file__)
# For Bootstrap
from reactflow_css.bootstrap import configure_boots
config_boots = configure_boots(__file__)
Getting Default Templates
Generate default CSS templates quickly:
# Get default Tailwind CSS template
from reactflow_css.tailwindcss import default_tailwind
tailwind_css = default_tailwind(path_output="./styles/tailwind.css")
# Get default Bootstrap template
from reactflow_css.bootstrap import default_boots
bootstrap_css = default_boots(path_output="./styles/bootstrap.css")
Parameters:
path_output(str, optional): File path to save the generated CSS content. IfNone, returns content as string only.
Tailwind CSS Integration
Step 1: Configure Tailwind
Set up your Tailwind configuration:
from reactflow_css.tailwindcss import configure_tailwind
config_tailwind = configure_tailwind(__file__)
# Define Tailwind configuration
tailwind_config = {
"content": ["./src/**/*.{js,ts,jsx,tsx,py}", "./templates/**/*.html"],
"theme": {
"extend": {
"colors": {
"primary": "#3b82f6",
"secondary": "#64748b"
}
}
},
"plugins": []
}
# Apply configuration
config_tailwind.config(tailwind_config)
Step 2: Setup Templates
Generate the necessary Tailwind files:
# Create tailwind.config.js and input.css files
config_tailwind.render_templates(
path_config="./tailwind.config.js",
path_index="./input.css"
)
# Or use default templates
config_tailwind.default_templates(path_output="./styles/")
Step 3: Compile CSS
Compile your Tailwind CSS:
# Compile with file paths
compiled_css = config_tailwind.compile(
path_config="./tailwind.config.js",
path_index="./input.css",
path_output="./dist/styles.css"
)
# Or compile with inline styles
compiled_css = config_tailwind.compile(
index="@tailwind base; @tailwind components; @tailwind utilities;",
path_output="./dist/styles.css"
)
Parameters:
path_config(str, optional): Path to tailwind.config.js filepath_index(str, optional): Path to input CSS filepath_output(str): Output path for compiled CSS (default: "output.css")index(str, optional): Inline CSS content instead of file*args: Additional flags for Tailwind CLI
Bootstrap Integration
Step 1: Setup Templates
Initialize Bootstrap templates:
from reactflow_css.bootstrap import configure_boots
config_boots = configure_boots(__file__)
# Render templates from existing files
template_content = config_boots.render_templates(path_index="./styles/custom.css")
Step 2: Configure Styles
Add custom styles and imports:
# Configure with custom styles and imports
custom_css = """
.custom-button {
background-color: #007bff;
border: none;
padding: 12px 24px;
border-radius: 4px;
}
"""
bootstrap_css = config_boots.config(
style=custom_css,
path_output="./dist/bootstrap-custom.css",
'@import "https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css";',
'@import "./additional-styles.css";',
'@import "--/css/bootstrap.min.css";'
)
if you use this format @import '--/...' (better use --/css/ is the module css styling from main folder of this pkg) then it will import the css module from the main folder of this pkg
Step 3: Use in ReactPy Components
Convert CSS imports to HTML link elements:
from reactpy import html, component
from reactflow_css.bootstrap import convert_imports_to_link
@component
def App():
return html.div(
convert_imports_to_link(style=bootstrap_css),
html.h1("Hello, Bootstrap!", className="text-primary"),
html.button("Click me!", className="btn btn-primary custom-button")
)
API Reference
Main Package (reactflow_css)
The main package provides convenient aliases for common functions:
configure_boots: Alias forbootstrap.Configuration.configureconfigure_tailwind: Alias fortailwindcss.Configuration.configuredefault_boots: Alias forbootstrap.Configuration.default_cssdefault_tailwind: Alias fortailwindcss.Configuration.default_cssconvert_imports_to_link: Alias forbootstrap.generate.Convert_style
Tailwind CSS Module (reactflow_css.tailwindcss)
Class: configure
Main class for handling Tailwind CSS configuration and compilation.
__init__(self, __path__)
- Parameters:
__path__- Path to the main script for resolving relative paths - Purpose: Initializes the configure class
config(self, config_dict: Dict[str, Any] = None, **kwargs) -> str
- Parameters:
config_dict- Dictionary containing Tailwind CSS configuration**kwargs- Additional configuration as keyword arguments
- Returns: String representation of tailwind.config.js content
- Purpose: Generates Tailwind configuration content
render_templates(self, path_config: str = None, path_index: str = None) -> None
- Parameters:
path_config- Path to tailwind.config.js (default: "./tailwind.config.js")path_index- Path to input CSS file (default: "./input.css")
- Purpose: Loads Tailwind configuration and input CSS from files
default_templates(self, path_output: str = None) -> str
- Parameters:
path_output- Optional path to write default CSS content - Returns: Default CSS content as string
- Purpose: Returns default Tailwind CSS template
compile(self, path_config: str = None, path_index: str = None, path_output: str = "output.css", index: str = None, *args) -> str
- Parameters:
path_config- Path to tailwind.config.js filepath_index- Path to input CSS filepath_output- Output path for compiled CSSindex- Optional inline CSS content*args- Additional Tailwind CLI arguments
- Returns: Generated CSS content as string
- Purpose: Compiles Tailwind CSS
Function: default_css(path_output: str = None) -> str
- Parameters:
path_output- Optional path to write default CSS content - Returns: Default Tailwind CSS content
- Purpose: Returns default CSS from package's output.css file
Exceptions
TailwindError(Exception): Base exception for Tailwind-related errorsModuleNotFound(TailwindError, ImportError): Required module not foundProcessError(TailwindError, RuntimeError): Process execution errorsConfigurationError(TailwindError): Invalid Tailwind configurationFileNotFoundError(TailwindError): Specified file not foundCompilationError(TailwindError): CSS compilation errorsValidationError(TailwindError): Validation failures
Bootstrap Module (reactflow_css.bootstrap)
Class: configure
Main class for handling Bootstrap configuration.
__init__(self, __path__)
- Parameters:
__path__- Path to main script for resolving relative paths - Purpose: Initializes the configure class
render_templates(self, path_input: str) -> str
- Parameters:
path_input- Path to input file - Returns: Content of rendered template
- Purpose: Renders templates from given input path
config(self, style: str = "", output: str = None, *args) -> str
- Parameters:
style- CSS content stringoutput- Optional path to write configured CSS*args- Additional import statements
- Returns: Final CSS content including imports
- Purpose: Configures Bootstrap styles with imports
Function: default_css(path_output: str = None) -> str
- Parameters:
path_output- Optional path to write default CSS content - Returns: Default Bootstrap CSS content
- Purpose: Returns default Bootstrap CSS from bootstrap.min.css
Component: Convert_style(style: str)
- Parameters:
style- CSS string containing @import statements - Returns: List of ReactPy html.link elements
- Purpose: Converts CSS @import rules to HTML link elements
Exceptions
BootsTrapError(Exception): Base exception for Bootstrap-related errorsModuleNotFound(BootsTrapError, ImportError): Required module not foundProcessError(BootsTrapError, RuntimeError): Process execution errorsConfigurationError(BootsTrapError): Configuration errorsFileNotFoundError(BootsTrapError): Specified file not foundCompilationError(BootsTrapError): CSS compilation errorsValidationError(BootsTrapError): Validation errors
Advanced Usage Examples
Custom Tailwind Configuration
from reactflow_css.tailwindcss import configure_tailwind
config_tailwind = configure_tailwind(__file__)
# Advanced Tailwind configuration
advanced_config = {
"content": ["./src/**/*.{js,ts,jsx,tsx,py}"],
"theme": {
"extend": {
"fontFamily": {
"sans": ["Inter", "sans-serif"]
},
"spacing": {
"18": "4.5rem",
"88": "22rem"
}
}
},
"plugins": ["@tailwindcss/forms", "@tailwindcss/typography"]
}
config_tailwind.config(advanced_config)
config_tailwind.render_templates()
# Compile with additional flags
compiled_css = config_tailwind.compile(
"--minify",
"--watch",
path_output="./dist/tailwind.min.css"
)
Bootstrap with Custom Imports
from reactflow_css.bootstrap import configure_boots
from reactpy import html, component
config_boots = configure_boots(__file__)
# Configure with multiple imports
custom_bootstrap = config_boots.config(
style="""
.navbar-custom {
background-color: #2c3e50;
}
.btn-custom {
background-color: #e74c3c;
border-color: #c0392b;
}
""",
path_output="./dist/custom-bootstrap.css",
'@import "https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css";',
'@import "https://fonts.googleapis.com/css2?family=Roboto:wght@300;400;500&display=swap";'
)
@component
def CustomApp():
return html.div(
convert_imports_to_link(style=custom_bootstrap),
html.nav(
html.div(
html.a("My App", href="#", className="navbar-brand"),
className="container"
),
className="navbar navbar-expand-lg navbar-custom"
),
html.div(
html.button("Custom Button", className="btn btn-custom"),
className="container mt-4"
)
)
Best Practices
- File Organization: Keep your CSS files organized in a dedicated
styles/orassets/directory - Configuration Management: Store Tailwind configurations in separate files for complex projects
- Performance: Use minification flags for production builds
- Caching: Cache compiled CSS to avoid unnecessary recompilation
- Error Handling: Always wrap compilation calls in try-catch blocks
Troubleshooting
Common Issues
- Module Not Found: Ensure all required dependencies are installed
- Compilation Errors: Check your Tailwind configuration syntax
- File Not Found: Verify file paths are correct and files exist
- Process Errors: Ensure Node.js and npm are properly installed for Tailwind
Debug Mode
Enable debug mode for detailed error information:
try:
compiled_css = config_tailwind.compile(
path_config="./tailwind.config.js",
path_index="./input.css",
"--verbose"
)
except Exception as e:
print(f"Compilation failed: {e}")
Contributing
We welcome contributions! Please follow these steps:
- Fork the repository
- Create a feature branch (
git checkout -b feature/new-feature) - Commit your changes (
git commit -am 'Add new feature') - Push to the branch (
git push origin feature/new-feature) - Create a Pull Request
License
This project is licensed under the MIT License - see the LICENSE file for details.
Support
For issues and questions:
- Create an issue on GitHub
- Check the documentation for common solutions
- Review the API reference for detailed usage information
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file reactflow_css-1.0.6.tar.gz.
File metadata
- Download URL: reactflow_css-1.0.6.tar.gz
- Upload date:
- Size: 1.5 MB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.11
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
490bf9341a472504abebb0d484b613a977cd64d6973e785fb8be9e143dfcf601
|
|
| MD5 |
f515f736e9d07ff7a83ab7d244374ff6
|
|
| BLAKE2b-256 |
cb2077ebacbe57aff404e8b640ea76eb1c9daeaf46ec9626749ae8cec0280102
|
File details
Details for the file reactflow_css-1.0.6-py3-none-any.whl.
File metadata
- Download URL: reactflow_css-1.0.6-py3-none-any.whl
- Upload date:
- Size: 1.6 MB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.11
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0f3970659e29ee2a26820641d9f7df38f365bdba60137aa39c828ee487677081
|
|
| MD5 |
e2a153e2b32ecd17c954ec56d104c3e2
|
|
| BLAKE2b-256 |
4b5fedd0da392ea15cce33de80982ee272de1c87e4371d072636f96fb3a8e635
|