Overview
The JobClient class provides methods for submitting jobs to SyftBox, managing job status, and querying jobs across datasites.
Factory Function
get_client()
Create a JobClient from a SyftBox folder.
Path to the SyftBox folder
Optional target user email for job views (defaults to root email)
Configured JobClient instance
JobClient Class
Constructor
from syft_job import JobClient, SyftJobConfig
config = SyftJobConfig.from_syftbox_folder(
syftbox_folder_path="/path/to/syftbox",
email="[email protected]"
)
client = JobClient(config, target_datasite_owner_email="[email protected]")
Configuration object for the job system
target_datasite_owner_email
Email of the datasite owner whose jobs to manage (defaults to config.email)
Methods
submit_python_job()
Submit a Python job to a user’s datasite.
job_path = client.submit_python_job(
user="[email protected]",
code_path="./my_script.py",
job_name="Data Analysis",
dependencies=["numpy", "pandas==1.5.0"],
entrypoint="main.py" # For folder submissions
)
Email address of the user to submit job for
Path to Python file or folder containing Python code
Name of the job (defaults to “Job - ”)
List of Python packages to install (e.g., [“numpy”, “pandas==1.5.0”])
Entry point file name for folder submissions (auto-detected if not provided)
Path to the created job directory
Auto-detection rules:
- For folders: Looks for
main.py first, then single .py file at root
- For files: Uses the file name as entrypoint
Example with folder:
# Submitting a project folder
job_path = client.submit_python_job(
user="[email protected]",
code_path="./my_project",
job_name="ML Training",
dependencies=["scikit-learn", "numpy"],
entrypoint="main.py"
)
submit_bash_job()
Submit a bash script job to a user’s datasite.
script = """#!/bin/bash
echo "Processing data..."
python analyze.py
"""
job_path = client.submit_bash_job(
user="[email protected]",
script=script,
job_name="Batch Processing"
)
Email address of the user to submit job for
Bash script content to execute
Name of the job (defaults to “Job - ”)
Path to the created job directory
setup_ds_job_folder_as_do()
Create a data scientist-specific job subdirectory with write permissions.
Email of the data scientist to create the folder for
Path to the created DS job folder
get_job_status()
Get the status of a job based on marker files.
status = client.get_job_status(job_path)
# Returns: "inbox", "approved", or "done"
Path to the job directory
Job status: “inbox”, “approved”, or “done”
Status Check Methods
# Check if job is approved
is_approved = client.is_job_approved(job_path)
# Check if job is done
is_done = client.is_job_done(job_path)
# Check if job is in inbox
is_inbox = client.is_job_inbox(job_path)
Path to the job directory
True if job is in the specified status
Properties
jobs
Get all jobs from all peer directories as an indexable list.
# Get all jobs
all_jobs = client.jobs
# Access by index
first_job = client.jobs[0]
# Access by name
my_job = client.jobs["Data Analysis"]
# Iterate over jobs
for job in client.jobs:
print(f"{job.name}: {job.status}")
# Display in Jupyter
print(client.jobs) # Shows formatted tables
JobsList containing all jobs grouped by user, sorted by submission time
Configuration
SyftJobConfig
Configuration object for the job system.
from syft_job import SyftJobConfig
config = SyftJobConfig.from_syftbox_folder(
syftbox_folder_path="/path/to/syftbox",
email="[email protected]"
)
Path to the SyftBox folder
Configuration Fields:
Path to SyftBox root folder
Helper Methods:
Complete Example
from syft_job import get_client
# Initialize client
client = get_client(
syftbox_folder_path="~/.syftbox",
email="[email protected]"
)
# Submit a Python job
job_path = client.submit_python_job(
user="[email protected]",
code_path="./analysis.py",
job_name="Monthly Report",
dependencies=["pandas", "matplotlib"]
)
print(f"Job submitted to: {job_path}")
# Check all jobs
for job in client.jobs:
if job.status == "inbox":
print(f"New job: {job.name} from {job.submitted_by}")