Skip to main content

PDCP - Pythonic DCP Wrapper

PDCP is a Python package that provides a more Pythonic interface to the DCP Python SDK (Bifrost2). It simplifies the interaction with DCP services by providing a clean, type-hinted interface for job management and computation.

Features

  • Type-Safe Configuration: Full type hints using TypedDict for job configuration
  • Event Handling: Flexible event subscription system for job monitoring
  • Job Chaining: Basic workflow management through job chaining
  • Compute Groups: Support for DCP compute group management
  • Streaming Slices: Optional streaming support for job slices

Requirements

PDCP requires a python version between [3.10, 4.0) and the latest node version.

You also need to have your keystore files located in your home directory as shown below for dcp to identify you.

└── %USERPROFILE%/.dcp
    ├── default.keystore
    └── id.keystore

Installation

pip install pdcp

Quick Start

from pdcp import Job, dcp
from pdcp.custom_types import JobConfig

# Define your work function
def work(x, a):
    dcp.progress()
    return x * a

# Configure your job
config: JobConfig = {   
    "name": "test",
    "work_function": work,
    "slices": [1, 2, 3],
    "constant_params": [3],
    "compute_groups": [{"joinKey": "group_name", "joinSecret": "secret"}]
}

# Create and configure the job
job = Job(config)

# Subscribe to job events
job.subscribe_to({
    "readystatechange": print,
    "accepted": lambda _: print(f'accepted: {job.id}'),
    "result": lambda e: print(f'result: {e.result}'),
    "status": lambda e: print(f'status: {e.runStatus}')
})

# Execute the job
job.dispatch()
results = job.get_results()
print(results)

Job Configuration

The JobConfig TypedDict provides a type-safe way to configure jobs:

class JobConfig(TypedDict):
    name: str                                           # Name of the job
    work_function: callable                             # Function to be executed
    slices: NotRequired[list]                           # Input data slices
    stream_slices: NotRequired[bool]                    # Enable/disable slice streaming
    constant_params: NotRequired[list[any]]             # Constant parameters for work function
    compute_groups: NotRequired[list[ComputeGroup]]     # DCP compute groups
    job_dependencies: NotRequired[list[str]]            # Required local dependencies

Event Handling

Jobs support various events that can be subscribed to:

from pdcp.types import EventHandler

events: EventHandler = {
    "readystatechange": handler,    # Job state changes
    "accepted": handler,            # Job accepted by DCP
    "result": handler,              # New result available
    "complete": handler,            # Job completed
    "console": handler,             # Console output
    "status": handler               # Status updates
}

job.subscribe_to(events)

Job Chaining

Basic job chaining is supported through the chain method:

# Create and chain jobs
job1 = Job(config1)
job2 = job1.chain(config2)

job1.dispatch()

Compute Groups

Support for DCP compute groups:

config: JobConfig = {
    "name": "my_job",
    "work_function": work,
    "compute_groups": [
        {
            "joinKey": "group_name",
            "joinSecret": "secret"
        }
    ]
}

Streaming Slices

Enable streaming slices for continuous data processing:

config: JobConfig = {
    "name": "streaming_job",
    "work_function": work,
    "stream_slices": True,  # Enable streaming
    "slices": initial_slices
}

job = Job(config)
# Add more slices later
job.add_slices(new_slices)

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

License

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

Metadata

Release files for pdcp 1.2.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 pdcp 1.2.0
File Size Uploaded
pdcp-1.2.0.tar.gz 4.3 kB Details

Built distribution (wheel)

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

Total release size: 10.1 kB

Release files / pdcp-1.2.0.tar.gz

Download URL pdcp-1.2.0.tar.gz
Size 4.3 kB
Tags Source
SHA-256 checksum
How to use checksums
0669ea367ced6660593a306ba1819231929212210d2d679f89574575feaa4826
BLAKE2b-256 checksum
How to use checksums
5d25319045d0ef4a3053ed96ae93fdee5c2c944d9e85cfc6545566865c9d94e5
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/2.1.3 CPython/3.11.12 Linux/6.11.0-1014-azure

Release files / pdcp-1.2.0-py3-none-any.whl

Download URL pdcp-1.2.0-py3-none-any.whl
Size 5.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
710aec694f8e971d823dbb64b0f39c73c1cab06223a05e6f2d3ee84efcf244b9
BLAKE2b-256 checksum
How to use checksums
af5af3db7d3ac65b3849f71a1c3c9c2938a2fd6457e1c7ddb37841a99d0488ce
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/2.1.3 CPython/3.11.12 Linux/6.11.0-1014-azure

Release history Release notifications | RSS feed

This release

1.2.0 This release

2 release files

1.1.0

2 release files

1.0.0

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