pytest-fsd
Validate Feature-Sliced Design (FSD) architecture in a Python project using pytest. The rules are adapted from the Steiger FSD plugin, with Python-specific checks where appropriate. This is an independent Python package, not an official Steiger port.
The applicable upstream changes are tracked through Steiger 0.7.0 / FSD plugin 0.8.0. See the changelog for Python adaptations.
Install
pip install pytest-fsd
# or
uv add --dev pytest-fsd
Python 3.8–3.14 is supported.
Use
Add the layers used by your project, from highest to lowest, to pyproject.toml:
[tool.pytest_fsd]
base_path = "src"
layers = ["app", "pages", "widgets", "features", "entities", "shared"]
# ignore_paths = ["my_non_fsd_package"]
Create an architecture test:
# tests/test_architecture.py
from pytest_fsd import validate_fsd_architecture
def test_architecture():
validate_fsd_architecture()
Run pytest tests/test_architecture.py. Violations appear as assertion failures with a rule name and path. If your source root is different, set base_path accordingly. The validator reads [tool.pytest_fsd] from the project root; validate_fsd_architecture(project_root="...") can target another project.
Standalone checks also raise AssertionError on violations and return a nonzero exit status:
python -c "from pytest_fsd import validate_fsd_architecture; validate_fsd_architecture()"
Unknown configuration keys/rules and invalid settings raise ValueError. A missing source root, uninspectable Python file, or symlink inside configured layers fails validation. ignore_paths excludes non-FSD top-level directories from the layer-name check; it does not suppress imports in configured layers.
Rules
The default checks cover layer import direction (forbidden-imports), slice independence (no-cross-imports), public APIs (public-api, no-public-api-sidestep, no-layer-public-api), structure (no-segmentless-slices, no-segments-on-sliced-layers, typo-in-layer-name, ambiguous-slice-names), naming (segments-by-purpose, repetitive-naming), and no-ui-in-app.
segments-by-purpose includes the generic names added in Steiger's FSD plugin 0.7.0, such as schemas, handlers, fixtures, middlewares, validators, resolvers, mutations, and assets. These names are checked when used as FSD segments. Python fixtures.py in a slice is also flagged because this package checks file segments as well as directories.
no-ui-in-app rejects an app/ui directory, as in Steiger. It also retains the Python-specific check for direct imports of common desktop GUI frameworks from the app layer.
Enable additional checks only when they suit your project:
[tool.pytest_fsd]
base_path = "src"
layers = ["app", "pages", "widgets", "features", "entities", "shared"]
extra_rules = [
"excessive-slicing", # More than 20 slices per layer
"shared-lib-grouping", # More than 15 loose Python files in shared/lib
"no-file-segments", # Segments must be directories
"no-reserved-folder-names", # No nested segment names such as model/model
"no-wildcard-exports", # No `from module import *` in __init__.py
]
no-wildcard-exports was added in Steiger FSD plugin 0.8.0 and is disabled by default in both packages. It checks __init__.py files on every configured layer, including nested packages. Explicit module imports such as from . import model as model remain valid in Python. AST import diagnostics include line and character column numbers.
no-file-segments is a Python package option; it is not registered as a rule in Steiger FSD plugin 0.8.0. no-cross-imports is enabled here for compatibility, whereas the upstream plugin does not enable it by default. These choices are intentionally different from Steiger.
See the rule documentation for examples and details.
Scope and limitations
- Import rules statically inspect Python syntax, including relative imports, package initializers, function-local imports and
if TYPE_CHECKING:branches. They do not execute project code. Programmatic imports throughimportlib.import_module,importlib.__import__, and built-in__import__are analyzed too. Loader aliases, literal names, constant bindings, concatenation, f-strings, joins, relative packages and fromlists are supported. Literalexec/evalstrings and literalcompileinputs are inspected recursively, with bounded expansion. Unresolved recognized loader calls or executed code fail with[dynamic-imports]; they do not silently pass. Arbitrary user-defined import hooks and runtime code are not executed. no-public-api-sidestepsupports static__all__lists/tuples, concatenation, annotations,+=,appendandextend. Unresolved dynamic exports are reported as unknown.- Steiger's
inconsistent-namingandimport-localityhave no direct equivalent here. Consider Ruff'sNandTIDrules for Python naming and relative imports; their behavior is not identical to Steiger's rules. - Steiger's
insignificant-sliceneeds an import graph and is not implemented. The deprecatedprocesseslayer is not created by this package; omit it fromlayers. - This package checks Python files and filesystem structure. It does not implement every Steiger rule or every JavaScript-specific convention.
For example, this computed sibling import is rejected:
import importlib
layer = "features"
importlib.import_module(f"src.{layer}.other_slice")
If the target comes from runtime input (importlib.import_module(requested_module)), validation fails with [dynamic-imports] because the target cannot be proven valid. Replace it with an explicit dispatch between statically known imports. The checker is an architecture linter; it does not emulate arbitrary Python execution or serve as an execution sandbox.
See the upstream FSD plugin changelog for Steiger's release history.
License
MIT. See LICENSE.
Metadata
Release files for pytest-fsd 0.6.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| pytest_fsd-0.6.0.tar.gz | 34.7 kB | Without provenance | Details for pytest_fsd-0.6.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| pytest_fsd-0.6.0-py3-none-any.whl | Python 3 | none | any | Details for pytest_fsd-0.6.0-py3-none-any.whl |
Total release size: 90.6 kB
Release files / pytest_fsd-0.6.0.tar.gz
| Download URL | pytest_fsd-0.6.0.tar.gz |
|---|---|
| Size | 34.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
5c1bbf29a38b9f93681e29d957631a266e69b296edf192bafc312af369abad77
|
|
BLAKE2b-256 checksum How to use checksums |
91b98c7a05464ed45d4d6592bb0d76f41b3a1f6d9a7b849d7c3f4b5a49e7241b
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
uv/0.13.5 {"installer":{"name":"uv","version":"0.13.5","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"26.04","id":"resolute","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
|
Release files / pytest_fsd-0.6.0-py3-none-any.whl
| Download URL | pytest_fsd-0.6.0-py3-none-any.whl |
|---|---|
| Size | 55.9 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
3debaa4098c549abfee7f1eb6193be6df46de8e6a4ac43f229f13d5ac07342cb
|
|
BLAKE2b-256 checksum How to use checksums |
0b54dc01ad63cab93a81686fa8bad88962d8bb90a9c9085e57eb2db63c29f612
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
uv/0.13.5 {"installer":{"name":"uv","version":"0.13.5","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"26.04","id":"resolute","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
|
Security for pytest-fsd 0.6.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.