j2fix
Consistent Jinja2 templates. Less manual cleanup.
j2fix is a command-line formatter for Jinja2 templates, designed around the
Arista AVD style guide
and the rules enforced by Arista Networks' j2lint.
It fixes spacing and statement indentation, then runs j2lint to report anything
that still needs your attention.
If you use yamllint to check YAML and yamlfix to tidy it, think of j2fix as
the formatting companion to j2lint. It is useful for network configuration
templates, Ansible projects, and other Jinja templates that follow Arista's style.
You do not need Arista devices or the AVD collection to use it.
An independent project. Not affiliated with or endorsed by Arista Networks.
Usage guide · Security policy · Report a bug
See the difference
Before:
{%for interface in interfaces%}
{%if interface.enabled%}
interface {{interface.name}}
description {{interface.description|default("Managed by automation")}}
{%endif%}
{%endfor%}
After j2fix interfaces.j2:
{% for interface in interfaces %}
{% if interface.enabled %}
interface {{ interface.name }}
description {{ interface.description | default("Managed by automation") }}
{% endif %}
{% endfor %}
Arista-style nesting goes inside the {% … %} delimiters. The indentation
of the configuration text itself stays intact in default mode.
Installation
Requires Python 3.10 or newer. Jinja2 and j2lint are installed automatically.
Install with pip
pip install j2fix
j2fix --version
Quick start
Preview the changes, then apply them:
j2fix --diff templates/
j2fix templates/
Check formatting and lint results without editing files:
j2fix --check templates/
You can pass several files or directories. With no path, j2fix searches the
current directory. Directory searches include .j2, .jinja, and .jinja2
files by default.
j2fix router.j2 switch.j2 templates/
j2fix --check .
j2fix --extensions j2,jinja,jinja2,html templates/
Useful commands
| What you want to do | Command |
|---|---|
| Format one file | j2fix router.j2 |
| Preview changes | j2fix --diff templates/ |
| Check formatting and lint | j2fix --check templates/ |
| Format without linting | j2fix --no-lint templates/ |
| Read from standard input | j2fix - < router.j2 |
| See all options | j2fix --help |
Exit codes: 0 means success; 1 means lint issues or changes found in check/diff
mode; 2 means a processing error or no matching files. Files may already have
been changed in write mode even when the command returns an error.
What to expect
- Spacing and statement indentation are fixed automatically.
- Invalid syntax, variable naming, and other unsupported fixes need manual attention.
- j2fix does not render templates or validate the resulting device configuration.
--unsafecan change rendered whitespace. Preview it withj2fix --unsafe --diff templates/and run your rendering tests before applying it.
The current source also adds symlink protection, atomic file replacement, and input limits. See file safety and limits.
Configuration
Optional settings go in your project's pyproject.toml:
[tool.j2fix]
extensions = ["j2", "jinja", "jinja2"]
exclude = [".git", ".venv", "venv", "build", "dist"]
unsafe = false
lint = true
tab_size = 4
j2fix searches upward from your current working directory for these settings.
exclude replaces the default exclusions. Keep unsafe = false unless you
intend to allow whitespace changes.
See the configuration guide for overrides and limits.
Use with pre-commit
Add this to .pre-commit-config.yaml:
repos:
- repo: https://github.com/AutoRocket/j2fix
rev: v0.3.0
hooks:
- id: j2fix
Then run:
python -m pip install pre-commit
pre-commit install
pre-commit run --all-files
The hook edits files. Add args: [--check] to check without editing.
This example uses the released tag, not unreleased changes on main.
Help and development
For bugs, open an issue with a small,
sanitized template, expected output, and your j2fix --version.
For security concerns, follow the security policy instead.
See the usage guide for rule coverage, the Python API, and development setup.
License
MIT.
Acknowledgments
This project is based on j2lint Arista Networks’ j2lint.
Metadata
Release files for j2fix 0.3.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 | |
|---|---|---|---|
| j2fix-0.3.0.tar.gz | 22.7 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| j2fix-0.3.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 36.7 kB
Release files / j2fix-0.3.0.tar.gz
| Download URL | j2fix-0.3.0.tar.gz |
|---|---|
| Size | 22.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
3dc17c8f118fc4c291de2bf77de0cf44af1a55a45d6249b1539e17976b0ca39f
|
|
BLAKE2b-256 checksum How to use checksums |
c2a8bb287487e8d7bebacdb8e9c61c736622117ced7cc53f1a441dddc82b29ab
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
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.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Sep 16, 2026.
Transparency logRelease files / j2fix-0.3.0-py3-none-any.whl
| Download URL | j2fix-0.3.0-py3-none-any.whl |
|---|---|
| Size | 13.9 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
72c6a11fdab27f4ef5dddf3c596f529db9dad26a041d086cb35c09176ec32ab5
|
|
BLAKE2b-256 checksum How to use checksums |
ede5ccb990e1e6e1f39620c2f6c537b18e9a104477698d9c0ee0faff3b32e32c
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
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.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Sep 16, 2026.
Transparency log