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.
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:
|
| RETURNS | DESCRIPTION |
|---|---|
int
|
Number of jobs deleted. |
client_heartbeat
Send a heartbeat for a registered client.
| PARAMETER | DESCRIPTION |
|---|---|
client_id
|
The client ID.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
bool
|
True if heartbeat successful, False otherwise. |
deactivate_client
Deactivate a client (graceful disconnect).
| PARAMETER | DESCRIPTION |
|---|---|
client_id
|
The client ID.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
bool
|
True if deactivation successful, False otherwise. |
extend_queue
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:
|
available_cpu
|
Filter jobs by available CPU (0 = no filter).
TYPE:
|
available_accelerators
|
Filter jobs by available accelerators (0 = no filter).
TYPE:
|
| RAISES | DESCRIPTION |
|---|---|
EmptyQueueError
|
If no jobs are pending. |
list_projects
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:
|
name
|
Human-readable name.
TYPE:
|
entity
|
Entity/organization the client belongs to.
TYPE:
|
description
|
Optional description.
TYPE:
|
available_cpu
|
Number of available CPUs.
TYPE:
|
available_accelerators
|
Number of available accelerators.
TYPE:
|
| 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:
|
job_id
|
The ID of the job to remove.
TYPE:
|
| 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:
|
available_cpu
|
New available CPU count (None = no change).
TYPE:
|
available_accelerators
|
New available accelerator count (None = no change).
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
bool
|
True if update successful, False otherwise. |