Skip to main content

A simple jinja2-based argument templatizer

Project description

PyPI Package Documentation Status Git tag Test status Code coverage

Fyoo is a simple argument templatizer that wraps around a command. CLIs exist for pretty much everything, isn’t it about time we started using them in our pipelines as they are? The best data flow code is code you don’t have to write.

Installation

pip install fyoo

Basic Usage

Fyoo can provide context to a subcommand’s arguments after --. All arguments to that subcommand become pre-rendered jinja2 templates.

Fyoo allows you to inject context into shell arguments in a few ways, --fyoo-set being the simplest and easiest to get started with.

fyoo \
  --set table=Employee \
  -- \
sqlite3 \
  'examples/Chinook_Sqlite.sqlite' \
  'select * from {{ table }} where date(HireDate) < "{{ date() }}"' \
  -csv -header
# ... csv results

This goes further than simple bash replacement, because you have the full template power of jinja2 between when arguments are processed and before the process is started.

Let’s use this sql template file now.

{%- if not table %}
  {{ throw("'table' required") }}
{%- endif %}

select count(*)
from {{ table }}
{%- if condition %}
  where ({{ condition }})
{%- endif %}

The template file contents are passed as a bash argument, but then fyoo renders the template before passing it to sqllite3 subcommand.

The -v/--verbose flag will show the executable before running it.

fyoo \
  --verbose \
  --jinja-template-folder ./tests/sql \
  --set table=Employee \
  --set condition='lower(Title) like "%sales%"' \
  -- \
sqlite3 \
  'examples/Chinook_Sqlite.sqlite' \
  '{% include "count.sql.jinja" %}' \
  -csv
# ["sqlite3", "examples/Chinook_Sqlite.sqlite", "\nselect count(*) as c\nfrom Employee\nwhere (lower(Title) like \"%sales%\")", "-csv"]
# 4

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

fyoo-1.1.0.tar.gz (10.7 kB view hashes)

Uploaded Source

Built Distribution

fyoo-1.1.0-py3-none-any.whl (10.1 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page