https://github.com/mattrobenolt/jinja2-cli
CLI for Jinja2
https://github.com/mattrobenolt/jinja2-cli
cli jinja2 python toml xml yaml
Last synced: 21 days ago
JSON representation
CLI for Jinja2
- Host: GitHub
- URL: https://github.com/mattrobenolt/jinja2-cli
- Owner: mattrobenolt
- License: bsd-2-clause
- Created: 2012-06-01T19:46:04.000Z (over 13 years ago)
- Default Branch: main
- Last Pushed: 2024-10-17T20:15:18.000Z (over 1 year ago)
- Last Synced: 2025-05-12T17:14:38.187Z (9 months ago)
- Topics: cli, jinja2, python, toml, xml, yaml
- Language: Python
- Size: 72.3 KB
- Stars: 548
- Watchers: 13
- Forks: 183
- Open Issues: 35
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- awesome-tools - jinja2-cli - CLI for Jinja2 (General Purpose Preprocessor / Snippets Manager)
README
# $ jinja2
The CLI for [Jinja2](https://jinja.palletsprojects.com/).
```
$ jinja2 template.j2 data.json
$ curl -s http://api.example.com | jinja2 template.j2
```
## Install
```
$ uv tool install jinja2-cli
$ pip install jinja2-cli
```
## Formats
Built-in: JSON, INI, ENV, querystring, TOML (Python 3.11+)
Optional formats via extras:
```
$ pip install jinja2-cli[yaml]
$ pip install jinja2-cli[xml]
$ pip install jinja2-cli[hjson]
$ pip install jinja2-cli[json5]
```
## Features
- Read data from files or stdin
- Define variables inline with `-D key=value`
- Custom Jinja2 extensions
- **Import custom filters** - see [Custom Filters](#custom-filters) below
- Full control over Jinja2 environment options
Run `jinja2 --help` for all options, or see [docs/](docs/) for full documentation.
## Custom Filters
Extend Jinja2 with your own filters or use Ansible's extensive filter library:
```bash
# Use custom filters
$ jinja2 template.j2 data.json -F myfilters
# Use Ansible filters
$ jinja2 template.j2 data.json -F ansible.plugins.filter.core
```
Example filter module:
```python
# myfilters.py
def reverse(s):
return s[::-1]
def shout(s):
return s.upper() + "!"
```
See [docs/filters.md](docs/filters.md) for complete documentation and examples.
## Used by
- [Dangerzone](https://github.com/freedomofpress/dangerzone) by Freedom of the Press Foundation
- [Elastic](https://github.com/elastic/logstash-docker) Docker images (Logstash, Kibana, Beats)
- [ScyllaDB](https://github.com/scylladb/scylla-machine-image) CloudFormation templates
- [800+ more](https://github.com/mattrobenolt/jinja2-cli/network/dependents) on GitHub
## Available in
[](https://pypi.org/project/jinja2-cli/)
[](https://formulae.brew.sh/formula/jinja2-cli)
[](https://search.nixos.org/packages?query=jinja2-cli)
[](https://aur.archlinux.org/packages/jinja2-cli)
[](https://pkgs.alpinelinux.org/package/edge/community/x86_64/jinja2-cli)
## Learn more
- [Jinja2 as a Command Line Application](https://thejeshgn.com/2021/12/07/jinja2-command-line-application/)
- [Combining jinja2-cli with jq and environment variables](https://www.zufallsheld.de/2025/06/30/templating-jinja-cli)