fscss

Python interface to FSCSS (Figured Shorthand CSS).
Compile .fscss → plain CSS from scripts, Flask/Django, or the CLI — without writing JavaScript. This package vendors the official Node compiler (xfscss) and runs it for you; it does not reimplement the language in Python.
Hub guide: hub.devtem.org/python-compiler
How it works
style.fscss
│
▼
Python API / CLI (this package)
│
│ node fscss/_vendor/xfscss/bin/fscss.js …
▼
xfscss (Node) ──► style.css
|
|
| Language |
Same as upstream FSCSS (currently 1.2.6). New engine releases are re-vendored here. |
| Runtime |
Node.js 20+ must be on PATH (node or nodejs). Not bundled. |
| Cost |
One Node process per compile — ideal for build steps, not a hot-reload daemon. |
| Network |
Only for remote @import (URLs / registry names). Local files compile offline. |
Requirements
- Python 3.7+ (tested 3.8–3.12)
- Node.js 20+ (global
fetch, Array.prototype.toReversed())
node --version # should be v20 or newer
Install
pip install fscss
From source:
git clone https://github.com/Omonire/fscss-py
cd fscss-py
pip install -e ".[dev]"
Quick start
style.fscss
$accent: #8f6bff;
@define card(sel:.card){`
@use(sel) {
px: 16px;
py: 14px;
rounded: 12px;
stack: 12px;
}
`}
body {
bg: #0b0a13;
color: $accent!;
ff: sans-serif;
}
@card(.panel)
Python
import fscss
fscss.compile_file("style.fscss", "style.css")
CLI
fscss style.fscss style.css
CLI
# Set up this machine/project (checks Python/OS/Node, offers to install Node)
fscss init
# Compile
fscss input.fscss [output.css] # shorthand for `fscss compile`
fscss compile input.fscss -o out.css
fscss compile input.fscss --check # exit 1 if output is out of date
fscss compile input.fscss --strict # warnings become exit 2
# Directories
fscss build static # compile every .fscss
fscss build static --check # CI drift check, writes nothing
fscss clean static [--dry-run] # delete generated .css files
# Environment
fscss doctor [--check] [--json] # read-only environment report
fscss env [--json] # resolved paths and versions
fscss report [--json] # paste-ready bug report
fscss completion bash|zsh|fish|powershell
fscss input.fscss --watch # recompile on change (~1s poll)
fscss --version
fscss init detects winget/choco/scoop/brew/apt/dnf/pacman/
zypper/apk, prints the install command, and asks [Y/n] before installing
Node.js 20+. Use --yes in non-interactive shells, FSCSS_NO_DOWNLOAD=1 to
forbid installation, and FSCSS_NODE to point at a specific Node binary.
Stdout/stderr from the compiler is printed. Exit codes: 0 success, 1
compile/check failure, 2 environment problem, 130 interrupted.
Python API
import fscss
| Function |
Returns |
Notes |
compile_file(input_path, output_path, *, cwd=None, timeout=None) |
str |
Runs the compiler; returns combined stdout/stderr (includes warnings). Raises RuntimeError on failure or timeout. |
compile_string(source, *, input_dir=".", output_path=None, timeout=None) |
str |
From a string. Without output_path, returns CSS only (warnings not included). |
compile |
— |
Alias of compile_file. |
compile_dir(directory, recursive=True) |
list[tuple[Path, Path]] |
Every .fscss → sibling .css. |
iter_fscss(directory, recursive=True) |
list[Path] |
Sorted discovery. |
watch_dir(directory, interval=1.0, callback=None) |
threading.Thread |
Daemon thread; recompiles on change. |
init_flask(app=None, *, directory=None, watch=None) |
None |
Compiles static folder; watches when app.debug is true. |
init_django(directory=None) |
None |
Defaults to <BASE_DIR>/static. |
Examples
import fscss
# String → CSS
css = fscss.compile_string("$c: red;\nbody{ color: $c!; }")
# Directory
for src, out in fscss.compile_dir("static"):
print(f"{src} -> {out}")
Flask
from flask import Flask
import fscss
app = Flask(__name__)
fscss.init_flask(app) # compile now; watch in debug
Django (e.g. in AppConfig.ready())
import fscss
fscss.init_django()
# or: fscss.init_django("path/to/static")
FSCSS syntax (short)
Full language docs: fscss.devtem.org.
/* Prefer variables before rules */
$c: red;
.card {
px: 16px;
py: 14px;
rounded: 12px;
shadow: 0 8px 24px rgba(0,0,0,.35);
}
.box { color: $c!; }
@define center(elem){`
@use(elem) {
display: flex;
align-items: center;
}
`}
@center(.hero)
@import((card, button) from "./ui.fscss")
Browser IDE (no Python): fscss.devtem.org/ide
Semantics & limitations
Worth knowing before filing a bug:
- Not a full CSS AST. Unrecognized syntax is often passed through; typos can yield invalid CSS instead of a hard error. FSCSS-oriented issues may warn; arbitrary CSS is not fully validated.
- Shorthands need a terminator. Prefer
bg: red; (semicolon). Compact forms without ; may not expand. Short aliases (px, rounded, …) also accept a closing }.
- No
c: color alias — use color:.
$var is order-sensitive. Declare variables before rules; keep braces readable. Declarations after a one-line rule can be dropped; odd line breaks can change var(--x) vs inlined values.
- Warnings are easy to miss. The compiler often exits
0 with warnings. compile_file returns that text; compile_string returns CSS only.
- Imports resolve relative to the input file (or
input_dir / cwd for strings).
- Process model: one Node process per call — no shared engine state across threads.
watch_dir serializes compiles on its thread.
@define bodies with braces should use backticks / the documented quoting form.
- Upstream engine issues (report to Figsh/xfscss): e.g. some array mutation forms,
$/var || fallback in 1.2.6. Wrapper-only bugs: Omonire/fscss-py/issues.
Development
pip install -e ".[dev]"
pytest -q
ruff check .
mypy fscss
CI: lint + tests on Ubuntu/Windows, Python 3.8–3.12, wheel/sdist + twine check.
fscss/
├── core.py # subprocess bridge
├── cli.py # argparse CLI (compile/watch/init/doctor/build/...)
├── environment.py # Python/OS/Node/engine/package-manager checks
├── node_install.py # install Node via the platform package manager
├── integrations.py # dir / watch / Flask / Django
└── _vendor/xfscss/ # pinned upstream (1.2.6)
To bump the engine: replace _vendor/xfscss, update version notes, run the suite.
Feedback
Early release (0.2.x). Real projects help most:
pip install fscss
- Compile an existing
.fscss file (CLI and API).
- Open an issue with:
fscss --version, Python, OS, node --version
- minimal input + actual output
- whether the same file works in upstream CLI / IDE
Upstream: Figsh/xfscss · Docs: fscss.devtem.org · Modules: fscss-ttr/FSCSS · Hub (Python): python-compiler
Developers Figsh -> Core Engineer
Omonire -> Python Engineer and Maintainer
Verify If FSCSS has been installed
pip show fscss
# This will check and give a litle description about FSCSS library and alsp its version
# Or Use
fscss --version
License
MIT — see LICENSE.\
Vendored compiler: MIT © Figsh — see fscss/_vendor/xfscss/LICENSE.
Engineered and Written by Omonire