nf-python @ 0.1.4
Summary
nf-python is a Nextflow plugin enabling seamless integration between Nextflow and Python scripts. Python scripts can be invoked as part of your Nextflow workflow, and arguments and outputs will be serialized back-and-forth automatically, making them available as native pythonic objects.
Get Started
To use the plugin in your Nextflow data pipelines, simply include it by writing include { pyFunction } from 'plugin/nf-python' and it will be downloaded and installed. For all setup options, please refer to the Nextflow plugins documentation.
nf-python requires a working python installation in the execution environment. By default, the python in path will be used. It is also possible to specify a path to a specific python executable or a conda environment. Either in the configuration file:
nf_python {
// Option 1
executable = '/usr/bin/python'
// Option 2
conda_env = ''
}
The supported values for the conda_env option are the same ones supported by Nextflow's native conda support, and is using the same configuration options. Here are a few options:
- A list of required packages (e.g.
conda_env = 'numpy biopython') - A conda configuration file (e.g.
conda_env = '/opt/task-env.yml') - A path to an existing conda environment (e.g.
conda_env = '/home/user/.conda/envs/my-env')
It is also possible to specify different environments on a per-function basis:
pyFunction(script: "", x: 1, y: 2, _executable: "/usr/bin/python")
pyFunction(script: "", x: 1, y: 2, _conda_env: "matplotlib")
Examples
To use a python script as part of your Nextflow pipeline, import pyFunction from the nf-python plugin:
include { pyFunction } from 'plugin/nf-python'
pyFunction('my_other_script.py', foo: 'too')
Usage inside python is easy:
- Arguments (like
foo) are passed asnf_python.nf.args. - To return results to nextflow, use
nf_python.nf.output(...) - All major native data types (lists, dicts, etc.) are supported.
# example_script.py
from nf_python import nf
# Access arguments and options
print(nf.args)
print(nf.opts)
# Assign output
nf.output(result=nf.args[0] + 1)
Inline Code Support
pyFunction also support inline code. Here is an example:
result = pyFunction("""
# Code is automatically de-indented correctly
# `nf_python.nf` is accessible as `nf`
nf.output(arg1=123, arg2='abc')
""")
assert result == [arg1: 123, arg2: 'abc']
result = pyFunction("""
nf.output(arg1=123, arg2='abc', arg3=nf.args['foo'])
""", foo: 1)
assert result == [arg1: 123, arg2: 'abc', arg3: 1]
License
See COPYING for license information. The layout of the project is based on the nf-hello project, licensed under the Apache License 2.0.
| Nextflow version | >=24.04.0 |
|---|---|
| Depends On | - |
| Release Date | 09 Jan 2026 13:50:38 (UTC) |
| Release Notes | - |
| Download URL | https://registry.nextflow.io/api/v1/plugins/nf-python/0.1.4/download/nf-python-0.1.4.zip |
| Store URL | https://public.cr.seqera.io/v2/nextflow/plugin/nf-python/blobs/sha256:022250a2c68a96bad589bc3515a3cab8fafcfdf1acc2a0b742fb040bd20f1b2c |
| Size | 31.1 KB |
| Checksum | 99d59cf3e396ea934480f6ad1571e9a4038c1cd4c80e6836ce769c5eba06d01f126be2b8ce7eea5ae5bd842634dcb6bfe6851797b06a60469130803ee9a14567 |
| Total downloads | 13 View trends |
| Security Scan |