Custom Pipelines

Pipelines are Python scripts; each contains a set of instructions that have to be executed in an orderly manner—pipe-like nature—to perform a code analysis.

  • A pipeline is a Python class that lives in a Python module as a .py file.

  • A pipeline class always inherits from the Pipeline base class Pipeline Base Class, or from other existing pipeline classes, such as the Built-in Pipelines.

  • A pipeline defines sequence of steps—execution order of the steps—using the steps classmethod.

See Pipelines for more details.

Pipeline registration

Built-in pipelines are located in scanpipe/pipelines/ directory and are registered during the installation.

Whereas custom pipelines are added as Python files .py in the directories defined in the SCANCODEIO_PIPELINES_DIRS setting. Custom pipelines are registered at runtime.

Create a Pipeline

Create a new Python file, and make sure to include the full path of the new pipeline directory in the SCANCODEIO_PIPELINES_DIRS setting.

from scanpipe.pipelines import Pipeline

class MyPipeline(Pipeline):

    def steps(cls):
        return (

    def step1(self):

    def step2(self):


You can view the scanpipe/pipelines/ directory for more pipeline examples.

Modify Existing Pipelines

Existing pipelines are flexible and can be reused as a base for custom pipelines , i.e. be customized. For instance, you can override existing steps, add new ones, or remove any of them.

from scanpipe.pipelines.scan_codebase import ScanCodebase

class MyCustomScan(ScanCodebase):

    def steps(cls):
        return (
            # Original steps from the ScanCodebase pipeline

            # Commented-out as not interested in a csv output
            # cls.csv_output,

            # My extra steps

    def extra_step1(self):

    def extra_step2(self):

Custom Pipeline Example

The example below shows a custom pipeline that is based on the built-in Scan Codebase pipeline with an extra reporting step.

Add the following code snippet to a Python file and register the path of the file’s directory in the SCANCODEIO_PIPELINES_DIRS.

from collections import defaultdict

from jinja2 import Template

from scanpipe.pipelines.scan_codebase import ScanCodebase

class ScanAndReport(ScanCodebase):
    Runs the ScanCodebase built-in pipeline steps and generate a licenses report.

    def steps(cls):
        return ScanCodebase.steps() + (

    # Set to True to extract recursively nested archives in archives.
    extract_recursively = False

    # See for documentation
    report_template = """
    {% for matched_text, paths in resources.items() -%}
        {{ matched_text }}

        {% for path in paths -%}
            {{ path }}
        {% endfor %}

    {% endfor %}

    def report_licenses_with_resources(self):
        Retrieves codebase resources filtered by license categories,
        Generates a licenses report file from a template.
        categories = ["Commercial", "Copyleft"]
        resources = self.project.codebaseresources.licenses_categories(categories)

        resources_by_licenses = defaultdict(list)
        for resource in resources:
            for license_data in resource.licenses:
                matched_text = license_data.get("matched_text")

        template = Template(self.report_template, lstrip_blocks=True, trim_blocks=True)
        report_stream =
        report_file = self.project.get_output_file_path("license-report", "txt")

Pipeline Packaging

Once you created a custom pipeline, you’ll want to package it as a Python module for easier distribution and reuse. You can check the Packaging Python Project tutorial at PyPA, for standard packaging instructions.

After you have packaged your own custom pipeline successfully, you need to specify the entry point of the pipeline in the setup.cfg file.

scancodeio_pipelines =
    pipeline_name = pipeline_module:Pipeline_class


Remember to replace pipeline_module with the name of the Python module containing your custom pipeline.

Pipeline Packaging Example

The example below shows a standard pipeline packaging procedure for the custom pipeline created in Custom Pipeline Example.

A typical directory structure for the Python package would be:

├── pyproject.toml
├── README.rst
├── setup.cfg
└── src
    └── scancodeio_scan_and_report_pipeline
        └── pipelines

Add the following code snippet to your setup.cfg file and specify the entry point to the pipeline under the [options.entry_points] section.

license_files =

name = scancodeio_scan_and_report_pipeline
author = nexB. Inc. and others
author_email =
license = Apache-2.0

# description must be on ONE line
description =  Generates a licenses report file from a template in
long_description = file:README.rst
url =
classifiers =
    Development Status :: 4 - Beta
    Intended Audience :: Developers
    Programming Language :: Python :: 3
    Programming Language :: Python :: 3 :: Only
keywords =

include_package_data = true
zip_safe = false
python_requires = >=3.8
setup_requires = setuptools_scm[toml] >= 4


scancodeio_pipelines =
    pipeline_name = scancodeio_scan_and_report_pipeline.pipelines.scan_and_report:ScanAndReport


Take a look at Google License Classifier pipeline for for a complete example on packaging a custom tool as a pipeline.

Pipeline Publishing to PyPI

After successfully packaging a pipeline, you may consider distributing it—as a plugin—via PyPI. Ensure a directory structure similar to the Pipeline Packaging Example with all package files correctly configured.


See the Python packaging tutorial at PyPA for a detailed setup guide.

Next step involves generating the distribution archives for the package. Make sure you have the latest version of build installed on your system.

pip install --upgrade build

Now run the following command from within the same directory where the pyproject.toml is located:

python -m build

Once completed, you should have two files inside the dist/ directory with the .tar.gz and .whl extensions.


Remember to create an account on PyPI before uploading your distribution archive to PyPI.

You can use twine to upload the package to PyPI. To install twine, run the following command:

pip install twine

Finally, you can upload your package to PyPI with the next command:

twine upload dist/*

Once successfully uploaded, your pipeline package should be viewable on PyPI under the name specified in your manifest.

To make your pipeline available in your instance of, you need to install the package from PyPI. For example, to install the package described in the Pipeline Packaging Example, run:

bin/pip install scancodeio_scan_and_report_pipeline