Integrations
Armonia is designed to be highly flexible and can be easily integrated into a wide variety of Python projects and ecosystems.
Flask/Django (Dynamic CSS)
Generate and serve CSS directly from your theme.
from armonia import Theme
from polychromos.color import HSLColor
theme = Theme()
# ... setup theme ...
def generate_theme_css(theme):
"""Generate CSS from theme."""
return "\n".join([
":root {",
theme.to_css_colors(),
"}",
"",
theme.to_css_fonts(),
])
# In your Flask view
@app.route('/theme.css')
def theme_css():
return generate_theme_css(theme), 200, {'Content-Type': 'text/css'}
TailwindCSS
Export theme colors to a configuration file compatible with Tailwind.
import json
def generate_tailwind_colors(theme):
"""Generate Tailwind color configuration."""
colors = {}
for entry in theme.get_all_colors():
colors[entry.name] = entry.color.to_css_hex()
config = {
"theme": {
"extend": {
"colors": colors
}
}
}
with open("tailwind.theme.json", "w") as f:
json.dump(config, f, indent=2)
Terminal & CLI Applications
Armonia works perfectly for colorizing terminal output using polychromos.
from armonia import Theme
from polychromos.color import HSLColor
theme = Theme()
# ... setup theme ...
def color_text(text, color_name):
color = theme.get_color(color_name)
# Use 24-bit true color ANSI codes
ansi_code = color.to_ansi_color(foreground=True, bits=24)
return f"{ansi_code}{text}\033[0m"
print(color_text("Success!", "success"))
Live Example
The repository includes a comprehensive interactive example in examples/color-showcase.py. To run it:
Then open http://localhost:5000 in your browser.