Skip to content

Server

The Server class is the main entry point for the WhatsNext client library.

Usage

from whatsnext.api.client import Server

# Connect to the server
server = Server("http://localhost:8000")

# Get all projects
projects = server.projects

# Get or create a specific project
project = server.get_project("my-project")

API Reference

Server

Client interface to the WhatsNext server.

Handles all HTTP communication with the server. This class is stateless - all job and project data is stored on the server.

append_project

append_project(
    name: str, description: str = ""
) -> Optional[Project]

Create a new project.

append_queue

append_queue(project: Project, job: Job) -> bool

Add a job to the project's queue.

clear_queue

clear_queue(project: Project) -> int

Clear all pending jobs from a project's queue.

PARAMETER DESCRIPTION
project

The project whose queue to clear.

TYPE: Project

RETURNS DESCRIPTION
int

Number of jobs deleted.

client_heartbeat

client_heartbeat(client_id: str) -> bool

Send a heartbeat for a registered client.

PARAMETER DESCRIPTION
client_id

The client ID.

TYPE: str

RETURNS DESCRIPTION
bool

True if heartbeat successful, False otherwise.

create_task

create_task(project: Project, task_name: str) -> bool

Create a new task for a project.

deactivate_client

deactivate_client(client_id: str) -> bool

Deactivate a client (graceful disconnect).

PARAMETER DESCRIPTION
client_id

The client ID.

TYPE: str

RETURNS DESCRIPTION
bool

True if deactivation successful, False otherwise.

delete_project

delete_project(project_name: str) -> bool

Delete a project by name.

extend_queue

extend_queue(
    project: Project, jobs: List[Job]
) -> List[int]

Add multiple jobs to a project's queue.

PARAMETER DESCRIPTION
project

The project to add jobs to.

TYPE: Project

jobs

List of Job objects to add.

TYPE: List[Job]

RETURNS DESCRIPTION
List[int]

List of created job IDs.

fetch_job

fetch_job(
    project: Project,
    available_cpu: int = 0,
    available_accelerators: int = 0,
) -> Dict[str, Any]

Fetch the next pending job from the queue.

PARAMETER DESCRIPTION
project

The project to fetch jobs from.

TYPE: Project

available_cpu

Filter jobs by available CPU (0 = no filter).

TYPE: int DEFAULT: 0

available_accelerators

Filter jobs by available accelerators (0 = no filter).

TYPE: int DEFAULT: 0

RAISES DESCRIPTION
EmptyQueueError

If no jobs are pending.

get_project

get_project(project_name: str) -> Optional[Project]

Get a project by name.

get_queue

get_queue(project: Project) -> List[Dict[str, Any]]

Get all pending jobs for a project.

list_projects

list_projects(
    limit: int = 10, skip: int = 0, status: str = "ACTIVE"
) -> None

Print a formatted table of projects.

register_client

register_client(
    client_id: str,
    name: str,
    entity: str,
    description: str = "",
    available_cpu: int = 0,
    available_accelerators: int = 0,
) -> bool

Register a client with the server.

PARAMETER DESCRIPTION
client_id

Unique client identifier.

TYPE: str

name

Human-readable name.

TYPE: str

entity

Entity/organization the client belongs to.

TYPE: str

description

Optional description.

TYPE: str DEFAULT: ''

available_cpu

Number of available CPUs.

TYPE: int DEFAULT: 0

available_accelerators

Number of available accelerators.

TYPE: int DEFAULT: 0

RETURNS DESCRIPTION
bool

True if registration successful, False otherwise.

remove_job

remove_job(project: Project, job_id: int) -> bool

Remove a specific job from a project's queue.

PARAMETER DESCRIPTION
project

The project containing the job.

TYPE: Project

job_id

The ID of the job to remove.

TYPE: int

RETURNS DESCRIPTION
bool

True if the job was removed, False otherwise.

update_client_resources

update_client_resources(
    client_id: str,
    available_cpu: Optional[int] = None,
    available_accelerators: Optional[int] = None,
) -> bool

Update a client's available resources.

PARAMETER DESCRIPTION
client_id

The client ID.

TYPE: str

available_cpu

New available CPU count (None = no change).

TYPE: Optional[int] DEFAULT: None

available_accelerators

New available accelerator count (None = no change).

TYPE: Optional[int] DEFAULT: None

RETURNS DESCRIPTION
bool

True if update successful, False otherwise.