A practical, Python-first tutorial for Flask, Django, and FastAPI developers.
I maintain the Python wrapper around FSCSS. The language and compiler are Figsh's work; my part is making FSCSS feel like a normal Python tool: pip install, a Python API, a CLI, and framework helpers.
This is the guide I wanted when I started wrapping the compiler.
What we will build
By the end of this tutorial, you will have a small Flask app that:
- stores styles in
static/src/site.fscss - compiles them to
static/src/site.css - uses variables, shorthands, and reusable mixins
- recompiles automatically in debug mode
- passes a CSS drift check in CI
The same patterns apply to Django, FastAPI, and plain Python scripts.
1. Install and verify
FSCSS requires:
- Python 3.7+ in package metadata, with CI covering 3.8-3.12
- Node.js 20+ on
PATH
Node is still required today because the Python package vendors the official xfscss compiler and runs it for you. The Node requirement is an implementation detail I want to remove later; the public API is Python.
python -m venv .venv
pip install fscss flask
Verify the install:
fscss --version
fscss doctor
fscss doctor is read-only. It checks Python, your OS, Node, and the vendored compiler path without modifying anything.
2. Your first .fscss file
Create style.fscss:
$accent: #8f6bff;
body {
bg: #0b0a13;
color: $accent!;
ff: system-ui, sans-serif;
}
Compile it:
fscss style.fscss style.css
You get plain CSS:
:root{--accent: #8f6bff;}
body {
background: #0b0a13;
color: #8f6bff;
font-family: sans-serif;
}
Three things happened:
-
$accentbecame a CSS custom property and was inlined where used. -
bgexpanded tobackground. -
ffexpanded tofont-family.
That is the core idea: write compact, semantic source; ship normal CSS.
3. How FSCSS thinks
FSCSS is not a utility-class framework. Your HTML keeps semantic class names like card, panel, and badge.
Variables
$accent: #8f6bff;
$surface: #12121a;
$text: #f7f5ff;
body {
bg: $surface!;
color: $text!;
}
Declare variables before the rules that use them. They are order-sensitive.
Shorthands
| FSCSS | CSS |
|---|---|
px: 16px; |
padding-left and padding-right
|
py: 14px; |
padding-top and padding-bottom
|
mx: auto; |
margin-left and margin-right
|
max-w: 360px; |
max-width |
rounded: 12px; |
border-radius |
stack: 12px; |
flex column with gap
|
bg: #12121a; |
background |
shadow: 0 8px 24px rgba(0,0,0,.35); |
box-shadow |
Always terminate shorthand declarations with ;.
Use color, not c. The c: alias is not supported by this engine version.
Reusable blocks
@define center(elem){`
@use(elem) {
display: flex;
justify-content: center;
align-items: center;
}
`}
@center(.hero)
The backticks matter when the body contains braces. This is one of the FSCSS quoting rules the Python wrapper preserves exactly from upstream.
4. Project layout
Create this structure:
dashboard/
??? app.py
??? requirements.txt
??? static/
? ??? src/
? ??? site.fscss
? ??? site.css
??? templates/
??? index.html
site.css is generated. You can commit it so production does not need to compile styles at startup.
5. Write the stylesheet
static/src/site.fscss:
$accent: #8f6bff;
$ink: #0b0a13;
$paper: #f7f5ff;
@define panel(sel:.panel){`
@use(sel) {
px: 24px;
py: 20px;
rounded: 16px;
shadow: 0 18px 50px rgba(0,0,0,.35);
stack: 14px;
}
`}
@define pill(sel:.pill){`
@use(sel) {
px: 14px;
py: 8px;
rounded: 999px;
}
`}
body {
bg: #0b0a13;
color: $paper!;
ff: system-ui, sans-serif;
padding: 40px;
}
main {
max-width: 760px;
margin: 0 auto;
}
h1 {
color: $accent!;
font-size: 42px;
}
code {
color: $accent!;
}
@panel(.card)
@pill(.badge)
Compile it directly once:
fscss static/src/site.fscss static/src/site.css
The generated site.css is ordinary CSS. No runtime JavaScript is involved.
6. Wire it into Flask
requirements.txt:
fscss>=0.2.0
flask>=2.2
app.py:
import os
from pathlib import Path
import fscss
from flask import Flask, render_template
BASE_DIR = Path(__file__).resolve().parent
STATIC_SRC = BASE_DIR / "static" / "src"
DEBUG = os.getenv("FLASK_DEBUG") == "1"
app = Flask(__name__)
app.debug = DEBUG
fscss.init_flask(app, directory=STATIC_SRC)
@app.get("/")
def index():
return render_template("index.html")
if __name__ == "__main__":
app.run(debug=DEBUG)
fscss.init_flask(app, directory=STATIC_SRC) does two things:
- Compiles every
.fscssfile inSTATIC_SRCimmediately. - Starts a daemon watcher when
app.debugis true.
templates/index.html:
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>FSCSS dashboard</title>
<link rel="stylesheet" href="{{ url_for('static', filename='src/site.css') }}">
</head>
<body>
<main>
<span class="badge">Flask + FSCSS</span>
<h1>Semantic CSS, compiled.</h1>
<div class="card">
<p>Edit <code>static/src/site.fscss</code> and refresh the page.</p>
<p>With <code>FLASK_DEBUG=1</code>, FSCSS recompiles changed files automatically.</p>
</div>
</main>
</body>
</html>
Run it:
python app.py
On Windows PowerShell, enable watch mode like this:
$env:FLASK_DEBUG = "1"
python app.py
7. Use the Python API directly
The Flask helper is built on top of the same API you can use anywhere.
Compile one file
import fscss
fscss.compile_file("static/src/site.fscss", "static/src/site.css")
compile_file returns the compiler's combined stdout/stderr. That output can include warnings even when the process exits 0.
Compile a string
import fscss
css = fscss.compile_string("$c: red;\nbody{ color: $c!; }")
print(css)
compile_string returns CSS only. If you need warnings, use file compilation or check the CLI output.
Compile a directory
import fscss
for src, out in fscss.compile_dir("static/src"):
print(f"{src} -> {out}")
Watch manually
import fscss
fscss.watch_dir("static/src", interval=1.0)
The watcher is a daemon thread intended for development. It polls source file mtimes and recompiles changed .fscss files to sibling .css files.
8. Django
For Django, call the helper from settings or an AppConfig.ready() method:
import fscss
fscss.init_django("path/to/static/src")
If you omit the path, the helper tries <BASE_DIR>/static.
Remember that compilation writes a sibling .css file. If your source is static/src/site.fscss, your template should load static/src/site.css.
9. FastAPI
There is no dedicated FastAPI helper yet, but the Python API is enough:
import fscss
from fastapi import FastAPI
from fastapi.staticfiles import StaticFiles
fscss.compile_file("static/src/site.fscss", "static/src/site.css")
app = FastAPI()
app.mount("/static", StaticFiles(directory="static"), name="static")
If you want development watching, start fscss.watch_dir("static/src") during local development only.
10. CI: catch stale CSS
Add this to CI after installing fscss:
- name: Set up Node.js
uses: actions/setup-node@v4
with:
node-version: '20'
- name: Install FSCSS
run: pip install fscss
- name: Check generated CSS
run: fscss build static/src --check
--check does not write files. It exits 1 if the committed CSS does not match the current .fscss source.
For a normal build step that fails on warnings, use:
fscss build static/src --strict
I recommend running --check in CI and --strict in your local or build-time compile step.
11. Debugging checklist
When something looks wrong, run:
fscss --version
fscss doctor
fscss env --json
fscss report --json
Common issues:
- Node is missing or too old. Install Node 20+.
- A shorthand did not expand. Add the semicolon.
-
A variable did not apply. Move
$varabove the rule that uses it. -
A warning was missed. Use
--strictor inspectcompile_fileoutput. -
An import failed. Local imports resolve relative to the input file; for strings, pass
input_diror set CLI--cwd. - A typo produced invalid CSS. The engine is not a full CSS AST validator.
If the same file fails in upstream FSCSS, report it to Figsh/xfscss. If it works upstream but fails through Python, open an issue at Omonire/fscss-py with a minimal reproducer.
12. When FSCSS is a good fit
Use FSCSS when you want:
- semantic class names
- design tokens
- mixins and compact shorthands
- plain CSS output
- zero runtime styling
- a Python-first developer experience
It may not be a fit if your team already has a mature Tailwind design system, needs full CSS AST validation, or wants to avoid Node entirely today.
Final thoughts
FSCSS belongs to the upstream community and Figsh. The Python wrapper is my attempt to make it comfortable for the Python web ecosystem: installable with pip, scriptable from Python, usable from Flask/Django/FastAPI, and safe to check in CI.
If anything in this tutorial feels awkward, that is useful feedback. Open an issue, include your fscss report --json output and a small .fscss file, and I will use it to improve the next release.
Links
- PyPI: https://pypi.org/project/fscss/
- GitHub: https://github.com/Omonire/fscss-py
- v0.2.0 release: https://github.com/Omonire/fscss-py/releases/tag/v0.2.0
- Upstream FSCSS docs: https://fscss.devtem.org/
- Shorthand reference: https://fscss.devtem.org/shorthands
- Python hub guide: https://hub.devtem.org/python-compiler
Suggested DEV.to tags: python, css, webdev, flask
Top comments (0)