Python client
DagnamClient, AsyncDagnamClient, resource modules, errors, long running operations, streaming, and retries.
Python client The dagnam package exposes a synchronous client, an async client, and a set of resource modules built on top of them. This page covers all three, plus the errors, long running operations, streaming, and retry behavior they share. Quick start Every top level API call dagnam.create training job , dagnam.inference , and so on takes client , api key and api url as keyword-only arguments, so you can mix module-level calls with an explicit client without re-authenticating. load dataset is the exception: it takes api url and api key but no client . Configuration in code dagnam.configure sets the key and URL used by every module-level call that does not pass its own api key= / api url= . See Install /docs/dag-lib/install for the full precedence order an explicit argument beats configure , which beats the environment, which beats the config file . Resource modules dagnam.resources groups the client into one module per domain; each is also importable from the package root as dagnam. . Module Covers ------------- ----------------------------------------------------------------------------------------------------------------------------------------------------- account Entitlements, storage quota, API key usage, public profiles. projects Create, list, update, duplicate, delete, thumbnails, architecture versions. codegen Generate, preview, validate and download model code. datasets Upload, deployments deploy model version , pause, resume, revisions, metrics, logs. hub Search, star, fork, publish and manage hub models. models Push, download, lineage and task contracts for the model registry; get and list entries with DagnamClient.get model entry and list model entries . foundation Fine-tune runs and evaluations against curated base models. studio build diagram state , to build a diagram state for a project. Training functions are re-exported at the top level rather than as dagnam.training , which is the local metrics reporter see Train on your own hardware /docs/training/own-hardware : create training job , get training job , list training jobs , cancel training job , delete training jobs , restart , restore checkpoint a new job from a checkpoint, under the same checks as restart , estimate resources , allowed strategies , download code , download dag , stream training , training logs , training metrics , training metrics summary , and download checkpoint job id, checkpoint id=None, , cache dir=None, prefer best=False latest checkpoint by default; pass prefer best=True for the best one instead . The client and the async client AsyncDagnamClient the aio extra exposes the same method names as async def and is used as an async context manager; most methods on it also have a synchronous counterpart with the same name on DagnamClient . The exceptions are async only: stream training events , stream deployment events , stream predict , download checkpoint and download model artifact . Resource helper functions such as preview dataset and inference are synchronous only; call the equivalent client method directly for async code. Errors Every error from an API call, including a failed connection, is a dagnam.DagnamError . Local helpers such as the dataset converters can also raise ValueError or TypeError for input they cannot handle. Exception When -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- ----------------------------------------------------------------- AuthError No or invalid credentials. APIError status code, message An HTTP error the SDK does not have a narrower type for. EmailNotVerifiedError The account has not verified its email yet. AccountSuspendedError The account is suspended. AccountLockedError The account is temporarily locked after repeated failed sign ins. DatasetNotFoundError , DeploymentNotFoundError , TrainingJobNotFoundError , CheckpointNotFoundError , HubModelNotFoundError , ModelNotFoundError , ProjectNotFoundError , and similar The id does not exist, or is not yours. QuotaExceededError A plan limit was hit. PayloadTooLargeError A request or file exceeded the size limit. LROTimeoutError A long running operation did not finish within its timeout. LROFailedError A long running operation finished in a failed state. CodegenValidationError , ArchitectureValidationError Code generation or the architecture failed validation. StreamError A streaming call failed. UploadError A file upload failed. RunFailedError A fine-tuning run ended failed, cancelled or timed out. Long running operations A handful of calls dataset URL import, deployment lifecycle actions, and more return a LongRunningOperation instead of a plain result: - .status returns the latest polled state as a dict. - .done is True once the operation reached a terminal state. - .wait timeout=300.0 polls with backoff until the operation finishes, and raises LROTimeoutError if it does not finish in time. - .result returns the final payload; call it after .wait . Streaming stream training job id, , last event id=None, include heartbeats=False, max reconnects=50 yields SSEEvent event, data, id, retry objects until the job reaches a terminal state, reconnecting on its own with Last-Event-ID when the connection drops. Sync streaming needs the streaming extra installed; the async client streams the same events through stream training events , stream deployment events and stream predict . See Streaming /docs/api/streaming for the underlying HTTP contract. Retries and idempotency DagnamClient retries a connection error, a 429 , or a 500 , 502 , 503 or 504 response up to 3 times with jittered backoff. It retries GET , HEAD , PUT and DELETE requests; a POST is retried only when the SDK sends an Idempotency-Key with it, which it does for create calls such as create training job , deploy model version , model registry pushes and fine-tune runs. The server deduplicates a repeated key only for creating a training job or a deployment, so only those retries are guaranteed never to create a duplicate. DagnamClient.deploy model version also takes your own idempotency key , to make a manual retry safe too.
Open in Dagnam.AI docs