Prefect integrations for Northflank platform
Project description
prefect-northflank
Prefect integrations for running flows on the Northflank platform.
This collection provides a Prefect worker that can execute flow runs as containerized jobs on Northflank's cloud platform, giving you powerful orchestration capabilities with Northflank's container-native infrastructure.
Installation
Install prefect-northflank with pip:
pip install prefect-northflank
Quick Start
-
Set up Northflank credentials:
from prefect_northflank import Northflank credentials = Northflank( api_token="your-northflank-api-token", ) credentials.save("northflank-creds")
-
Create a work pool:
prefect work-pool create --type northflank my-northflank-pool
-
Configure your deployment (prefect.yaml):
deployments: - name: my-northflank-deployment entrypoint: flows.py:my_flow work_pool: name: my-northflank-pool job_variables: credentials: "{{ prefect.blocks.northflank.northflank-creds }}" project_id: "your-northflank-project-id" deployment_external_image_path: "prefecthq/prefect:3-python3.12" billing_deployment_plan: "nf-compute-20"
-
Start a worker:
prefect worker start --pool my-northflank-pool
-
Deploy and run your flow:
prefect deploy --all prefect deployment run 'my-flow/my-northflank-deployment'
Configuration
Flattened Configuration Structure
The Northflank worker uses a flattened configuration structure to work with Prefect's JSON schema requirements. Complex nested objects are flattened using underscore notation:
billing.deploymentPlan→billing_deployment_plandeployment.external.imagePath→deployment_external_image_pathsettings.activeDeadlineSeconds→settings_active_deadline_seconds
This allows for easier configuration in YAML files and work pools while maintaining compatibility with the full Northflank API.
Worker Configuration
The Northflank worker supports the following configuration options:
| Parameter | Type | Description | Default |
|---|---|---|---|
| Core Configuration | |||
credentials |
Northflank | API credentials | Required |
project_id |
str | Northflank project ID | Required |
cleanup_job |
bool | Delete job after completion | True |
name |
str | Job name | Auto-generated |
description |
str | Job description | Auto-generated |
tags |
List[str] | Resource tags | None |
| Infrastructure | |||
infrastructure_architecture |
str | CPU architecture (x86/arm) | None |
| Billing | |||
billing_deployment_plan |
str | Resource allocation plan | "nf-compute-20" |
billing_gpu_enabled |
bool | Enable GPU support | False |
billing_gpu_type |
str | GPU type | None |
billing_gpu_count |
int | Number of GPUs | 1 |
billing_gpu_timesliced |
bool | Timesliced GPU sharing | None |
| External Deployment | |||
deployment_external_image_path |
str | Container image path | None |
deployment_external_credentials |
str | Registry credentials ID | None |
| Internal Deployment | |||
deployment_internal_id |
str | Build service ID | None |
deployment_internal_branch |
str | Git branch | None |
deployment_internal_build_sha |
str | Commit SHA to deploy | None |
deployment_internal_build_id |
str | Build ID to deploy | None |
| Docker Configuration | |||
deployment_docker_config_type |
str | Docker config type | "customCommand" |
deployment_docker_custom_command |
str | Custom command | None |
| Build Configuration | |||
build_configuration_docker_credentials |
List[str] | Docker credential IDs | None |
| Runtime | |||
runtime_environment |
Dict[str, str] | Environment variables | None |
| Settings | |||
settings_backoff_limit |
int | Retry attempts | 3 |
settings_active_deadline_seconds |
int | Job timeout (seconds) | 3600 |
settings_run_on_source_change |
str | Source change trigger | "never" |
Deployment Types
The Northflank worker supports three deployment strategies:
1. External Image Deployment (Default)
Deploy from a pre-built container image from any registry:
job_variables:
deployment_external_image_path: "prefecthq/prefect:3-python3.12"
deployment_external_credentials: "my-registry-creds-id" # Optional for private registries
2. Internal Build Service Deployment
Deploy from Northflank's build service output:
job_variables:
deployment_internal_id: "build-service-123"
deployment_internal_branch: "main"
deployment_internal_build_sha: "latest" # Or specific commit SHA
# OR
deployment_internal_build_id: "build-456" # Specific build ID
3. Docker Configuration
Control how the container runs:
job_variables:
deployment_docker_config_type: "customCommand"
deployment_docker_custom_command: "python my_script.py"
Note: Only one deployment type should be specified per job. If none is configured, the worker defaults to external deployment with the Prefect image.
Environment Variables
The worker automatically injects Prefect environment variables into job containers:
PREFECT_FLOW_RUN_ID: The unique flow run identifierPREFECT_FLOW_ID: The flow identifierPREFECT_API_URL: Prefect server/cloud API URL (if configured)PREFECT_API_KEY: Prefect API authentication key (if configured)
User-provided environment variables in runtime_environment take precedence over automatic variables.
Examples
Basic Flow Example
from prefect import flow
@flow
def my_flow():
print("Hello from Northflank!")
return "Flow completed successfully"
if __name__ == "__main__":
my_flow()
GPU Configuration Example
# prefect.yaml for GPU workloads
deployments:
- name: gpu-training
entrypoint: train_model.py:training_flow
work_pool:
name: northflank-gpu-pool
job_variables:
credentials: "{{ prefect.blocks.northflank.my-creds }}"
project_id: "proj-123456"
deployment_external_image_path: "nvidia/pytorch:23.10-py3"
billing_deployment_plan: "nf-gpu-h100-80-1g"
billing_gpu_enabled: true
billing_gpu_type: "h100-80"
billing_gpu_count: 2
settings_active_deadline_seconds: 14400 # 4 hours
runtime_environment:
CUDA_VISIBLE_DEVICES: "0,1"
TORCH_CUDA_ARCH_LIST: "8.9"
Build Service Deployment Example
# prefect.yaml for internal build service deployment
deployments:
- name: my-build-deployment
entrypoint: flows.py:my_flow
work_pool:
name: my-northflank-pool
job_variables:
credentials: "{{ prefect.blocks.northflank.my-creds }}"
project_id: "proj-123456"
deployment_internal_id: "build-service-abc123"
deployment_internal_branch: "main"
billing_deployment_plan: "nf-compute-50"
runtime_environment:
ENVIRONMENT: "production"
LOG_LEVEL: "info"
Authentication
API Token Setup
- Log in to your Northflank dashboard
- Navigate to Account Settings > Tokens
- Create a new API Role with appropriate permissions
- Select the Job General/Deployment scopes
- Create a new API Token using the role you just created
- Store the token securely using Prefect's block system
from prefect_northflank import Northflank
credentials = Northflank(api_token="nf-...")
credentials.save("my-northflank-creds")
Environment Variables
You can also set the API token via environment variable:
export NORTHFLANK_API_TOKEN="nf_..."
Development
Setup
-
Clone the repository:
git clone https://github.com/northflank/prefect-northflank.git cd prefect-northflank
-
Install with uv:
uv sync uv run python -m pip install -e .
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
License
This project is licensed under the Apache License 2.0 - see the LICENSE file for details.
Support
For support with this integration, please:
- Check the documentation
- Search existing issues
- Create a new issue if needed
Links
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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file prefect_northflank-1.0.0.tar.gz.
File metadata
- Download URL: prefect_northflank-1.0.0.tar.gz
- Upload date:
- Size: 963.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.8.17
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c4db4644f5f188bdd06efc2e007179496fa46f122d6a012ee30083058caf8e64
|
|
| MD5 |
aa7ee77fbb6835a5f04782b32b908ea0
|
|
| BLAKE2b-256 |
edda2e41a5541a8b55d2df163aaf53d1006b8df2b352c452e369a212ab29b89f
|
File details
Details for the file prefect_northflank-1.0.0-py3-none-any.whl.
File metadata
- Download URL: prefect_northflank-1.0.0-py3-none-any.whl
- Upload date:
- Size: 12.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.8.17
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f1fe3ed2030b1fd0b89a5056a8998e1a23ffc5095c792649770f176caa019815
|
|
| MD5 |
0d2b80a6da29f6451810501676663fe1
|
|
| BLAKE2b-256 |
53ee35ffdd83d3d660b1be5900bae6539cef9528f088faf2f0b26589ff62fe07
|