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 details)

Uploaded Source

Built Distribution

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

Uploaded Python 3

File details

Details for the file fyoo-1.1.0.tar.gz.

File metadata

  • Download URL: fyoo-1.1.0.tar.gz
  • Upload date:
  • Size: 10.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.0.0 CPython/3.10.1

File hashes

Hashes for fyoo-1.1.0.tar.gz
Algorithm Hash digest
SHA256 52d60f3df4e8a3040562657357cc7896198a0c0d5097048e6127af8a78efb44f
MD5 e361fb9fc636cac501973ddde36e73c2
BLAKE2b-256 b00b881e491b47fb271512a4520cf52461ca6af617229b3307dce22ce302a460

See more details on using hashes here.

File details

Details for the file fyoo-1.1.0-py3-none-any.whl.

File metadata

  • Download URL: fyoo-1.1.0-py3-none-any.whl
  • Upload date:
  • Size: 10.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.0.0 CPython/3.10.1

File hashes

Hashes for fyoo-1.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 fa97e6f8d00f06641971d79a3bb59cd331e00fec8fee09054db777c5ab8d22e4
MD5 1e06f597a9c1301048d5d83dc610ffb0
BLAKE2b-256 56a0249c8e075172118f9ccc565e7c53c1301225e112ed3ff4fa22d601d35d60

See more details on using hashes here.

Supported by

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