Fyoo¶
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
...
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
For complete how-to’s and arguments, see Usage.
Warning
Only pass context that you trust! Otherwise you may be leaving yourself wide open for Command Injection. Fyoo is suited for use-cases where you are still directly in control of template context.