Skip to main content

nFlow Client SDK

The nFlow Client SDK is a Python package designed for creating, managing, and executing media processing pipelines. It provides an easy-to-use interface for defining pipeline workflows, managing resources, and scheduling jobs.


Features

  • Define pipelines with modular operators.
  • Manage input and output resources.
  • Schedule pipeline jobs with cron-like triggers.
  • Track progress for long-running tasks (e.g., uploads, downloads, execution).
  • Designed for cloud-native environments.

Installation

To install the nflow-client-sdk, use pip:

pip install nflow-client-sdk

Quick Start

Here’s an example of using the SDK to define and execute a pipeline:

import asyncio
from nflow import Resource, Operator, Pipeline, Job, Trigger

# Progress callback for resources
def show_progress(progress):
    print(f"Progress: {progress:.2f}%")

async def main():
    # Step 1: Create resources
    input_resource = Resource("input_video", "collection_name", "file", "mp4")
    output_resource = Resource("output_stream", "collection_name", "live", "rtsp://localhost:8554/test")

    # Step 2: Upload input resource
    await input_resource.upload_async("/path/to/input", progress_callback=show_progress)

    # Step 3: Create operators
    loader = Operator("MP4FileLoaderOp", params={"resource_id": input_resource.id})
    brighten_op1 = Operator("BrightenConvOp", params={"brightness": 1.8})
    brighten_op2 = Operator("BrightenConvOp", params={"brightness": 1.8})
    sender = Operator("RTSPStreamSenderOp", params={"resource_id": output_resource.id})

    # Step 4: Create and link pipeline
    pipeline = Pipeline("my_pipeline")
    pipeline.link(loader, "video-out", brighten_op1, "video-in")
    pipeline.link(brighten_op1, "video-out", brighten_op2, "video-in")
    pipeline.link(brighten_op2, "video-out", sender, "video-in")
    pipeline.link(loader, "audio-out", sender, "audio-in")

    pipeline_id = pipeline.register()

    # Step 5: Schedule a job
    trigger = Trigger(cron="*/5 * * * *")
    job = Job(pipeline_id, trigger)
    job_id = job.start()
    print(f"Job '{job_id}' has been scheduled with trigger: {trigger.cron}")

    # Step 6: Run the job and wait for completion
    await job.run()
    print("Job completed!")

    # Step 7: Download the output resource
    await output_resource.download_async("/path/to/output", progress_callback=show_progress)
    print("Output resource downloaded!")

# Run the workflow
asyncio.run(main())

Operators

Operators are modular processing units that perform specific tasks in a pipeline. They encapsulate their behavior and parameters for easy integration into the pipeline workflow.

Available Operators:

  • MP4FileLoaderOp:

    • Purpose: Loads an MP4 file as input to the pipeline.
    • Parameters:
      • resource_id (str): The ID of the resource to load.
  • BrightenConvOp:

    • Purpose: Adjusts the brightness of video frames.
    • Parameters:
      • brightness (float): Brightness adjustment factor (e.g., 1.8).
  • RTSPStreamSenderOp:

    • Purpose: Sends the output of the pipeline as an RTSP stream.
    • Parameters:
      • resource_id (str): The ID of the output resource.

Pipelines

Pipelines define the logical flow of operations by linking operators. A pipeline manages how data flows from one operator to the next.

Creating a Pipeline

  1. Instantiate a Pipeline object:
    pipeline = Pipeline("my_pipeline")
    
  2. Add operators to the pipeline using the link() method:
    pipeline.link(source_operator, "output_pad_name", target_operator, "input_pad_name")
    
  3. Register the pipeline to prepare it for execution:
    pipeline_id = pipeline.register()
    

Jobs and Triggers

Jobs are responsible for executing pipelines, and triggers define when or how jobs are executed.

Scheduling a Job

  1. Define a trigger with a cron-like schedule:
    trigger = Trigger(cron="*/5 * * * *")  # Every 5 minutes
    
  2. Create a job and associate it with a pipeline:
    job = Job(pipeline_id, trigger)
    
  3. Start the job:
    job_id = job.start()
    
  4. Optionally, wait for the job to execute:
    await job.run()
    

License

This project is licensed under the MIT License. See the LICENSE file for details.


Contributing

Contributions are welcome! Please open an issue or submit a pull request.


Contact

For questions or support, please contact us at support@example.com.

Metadata

Release files for nflow 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for nflow 0.1.0
File Size Uploaded
nflow-0.1.0.tar.gz 5.3 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for nflow 0.1.0
File Interpreter ABI Platform
nflow-0.1.0-py3-none-any.whl Python 3 none any Details

Total release size: 11.4 kB

Release files / nflow-0.1.0.tar.gz

Download URL nflow-0.1.0.tar.gz
Size 5.3 kB
Tags Source
SHA-256 checksum
How to use checksums
19720d5d2b687f0c5511112db7894a3259d66dd71017ac9a1a0f3023685705ee
BLAKE2b-256 checksum
How to use checksums
c347678002ef19bf181735baf94faff386edba8dcc7e7b5182551a93848febe7
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.0.1 CPython/3.12.3

Release files / nflow-0.1.0-py3-none-any.whl

Download URL nflow-0.1.0-py3-none-any.whl
Size 6.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
c959676d0f9d3f83bc3ef6c9d90da6d00e438eba73d98914935df771482f2fbd
BLAKE2b-256 checksum
How to use checksums
db501cf0038a23aea16659e9246ec9ca2d8e1f84d99f5214019354cc3f02735c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.0.1 CPython/3.12.3

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page