Skip to main content

Fx (Function eXecution) in Python, inspired by https://www.npmjs.com/package/fx.

Project description

PyFx

The Python version of the non-interactive, JavaScript version of the fx. Short for PYthon Function eXecution or Pyf(x).

python3 -mpip install pyfx

Or install in develop mode:

git clone https://github.com/archeraldrich/pyfx
cd pyfx
python3 setup.py develop

Usage

PyFx treats arguments as Python expressions or functions. PyFx passes the input data to the first expression or function and then passes the result of the first one to the second one and so on.

echo '{"name": "world"}' | pyfx 'lambda x: x["name"]' 'lambda x: f"Hello, {x}!"'

Use self to access the input data. Use . at the start of the expression to access the input data without a lambda x: x part.

echo '{"name": "world"}' | pyfx '.get("name")' 'f"Hello, {self}!"'

Use other Python functions to process the data.

echo '{"name": "world"}' | pyfx 'dict.keys' 'list'

Advanced Usage

PyFx can process a stream of JSON objects. PyFx will apply arguments to each object.

printf '{"name": "hello"}\n{"name": "world"}' | pyfx '.get("name")'

If you want to process a stream of JSON objects as a single list, use the --slurp or -s flag.

printf '{"name": "hello"}\n{"name": "world"}' | pyfx --slurp 'list(map(lambda x: x.get("name"), self))' '", ".join'

If you want to process non-JSON data, use the --raw or -r flag.

ls | pyfx -r '[self, self.find(".md") != -1]'

You can use --raw and --slurp (or -rs) together to get a single array of strings.

ls | pyfx -rs 'list(filter(lambda x: x.find(".md") != -1, self))'

PyFx has a special symbol skip for skipping the printing of the result.

ls | pyfx -r 'self if self.find(".md") != -1 else skip'

PyFx comes with the import statement. Use the --import or -i command once per import statement, without the leading import keyword.

seq 1 100 | pyfx -rs -i 'numpy as np' -i 'from matplotlib import pyplot as plt' 'list(map(int, self))' 'np.array' 'plt.plot' 'lambda _: plt.show()'

License

MIT

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

pyfx-tool-0.1.0.tar.gz (4.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pyfx_tool-0.1.0-py3-none-any.whl (5.6 kB view details)

Uploaded Python 3

File details

Details for the file pyfx-tool-0.1.0.tar.gz.

File metadata

  • Download URL: pyfx-tool-0.1.0.tar.gz
  • Upload date:
  • Size: 4.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.9.16

File hashes

Hashes for pyfx-tool-0.1.0.tar.gz
Algorithm Hash digest
SHA256 6ac0ad6cc93191fee38e298f257c4179163c5377ede98a4dc0f040ab090949e1
MD5 495bee9338c95e15f5ae9bf00934606f
BLAKE2b-256 32e69f93f26d954c62a4f1b5912aa127eda6820170f7566a8b8d8702499ce4f6

See more details on using hashes here.

File details

Details for the file pyfx_tool-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: pyfx_tool-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 5.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.9.16

File hashes

Hashes for pyfx_tool-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 e1606bcf7d41531f5b519b6dc3fe3d6f05784cda3f33db432ce9af0cea38d3a2
MD5 374d2843cec8eac76887d3d5b0b89f67
BLAKE2b-256 35ad70c009862093a663e5a50729183c9a2ed378a8f6e36c9be311ca7d8b51e9

See more details on using hashes here.

Supported by

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