metafold package

Submodules

metafold.api module

metafold.api.asdatetime(s: str | datetime) datetime

Parse Metafold API datetime.

Note datetime strings returned by the Metafold API are RFC 1123 formatted, times are always in GMT.

Returns:

UTC datetime.

metafold.api.asdict(**kwargs: Any) dict[str, Any]

Convert present kwargs to dictionary.

metafold.assets module

class metafold.assets.Asset(*, id: str, filename: str, size: int, checksum: str, created: str | datetime, modified: str | datetime)

Bases: object

Asset resource.

id

Asset ID.

Type:

str

filename

Asset filename.

Type:

str

size

File size in bytes.

Type:

int

checksum

File checksum.

Type:

str

created

Asset creation datetime.

Type:

datetime.datetime

modified

Asset last modified datetime.

Type:

datetime.datetime

checksum: str
created: datetime
filename: str
id: str
modified: datetime
size: int
class metafold.assets.AssetsEndpoint(client: Client)

Bases: object

Metafold assets endpoint.

create(f: str | bytes | PathLike | IO[bytes]) Asset

Upload an asset.

Parameters:

f – File-like object (opened in binary mode) or path to file on disk.

Returns:

Asset resource.

delete(id: str) None

Delete an asset.

Parameters:

id – ID of asset to delete.

download_file(id: str, path: str | PathLike)

Download an asset.

Parameters:
  • id – ID of asset to download.

  • path – Path to downloaded file.

get(id: str) Asset

Get an asset.

Parameters:

id – ID of asset to get.

Returns:

Asset resource.

list(sort: str | None = None, q: str | None = None) list[Asset]

List assets.

Parameters:
  • sort – Sort string. For details on syntax see the Metafold API docs. Supported sorting fields are: “id”, “filename”, “size”, “created”, or “modified”.

  • q – Query string. For details on syntax see the Metafold API docs. Supported search fields are: “id” and “filename”.

Returns:

List of asset resources.

update(id: str, f: str | bytes | PathLike | IO[bytes]) Asset

Update an asset.

Parameters:
  • id – ID of asset to update.

  • f – File-like object (opened in binary mode) or path to file on disk.

Returns:

Updated asset resource.

metafold.client module

class metafold.client.Client(access_token: str, project_id: str, base_url: str)

Bases: object

Base client.

delete(url: str, *args: Any, **kwargs: Any) Response
get(url: str, *args: Any, **kwargs: Any) Response
patch(url: str, *args: Any, **kwargs: Any) Response
post(url: str, *args: Any, **kwargs: Any) Response
property project_id: str
put(url: str, *args: Any, **kwargs: Any) Response

metafold.exceptions module

exception metafold.exceptions.PollTimeout

Bases: Exception

Raised when a dispatched job failed to complete within expected time.

metafold.jobs module

class metafold.jobs.Job(*, id: str, name: str | None = None, type: str, parameters: dict[str, Any], created: str | datetime, state: str, assets: list[dict[str, Any] | Asset], meta: dict[str, Any])

Bases: object

Job resource.

id

Job ID.

Type:

str

name

Job name.

Type:

str | None

type

Job type.

Type:

str

parameters

Job parameters.

Type:

dict[str, Any]

created

Job creation datetime.

Type:

datetime.datetime

state

Job state. May be one of: pending, started, success, or failure.

Type:

str

assets

List of generated asset resources.

Type:

list[metafold.assets.Asset]

meta

Additional metadata generated by the job.

Type:

dict[str, Any]

assets: list[Asset]
created: datetime
id: str
meta: dict[str, Any]
name: str | None
parameters: dict[str, Any]
state: str
type: str
class metafold.jobs.JobsEndpoint(client: Client)

Bases: object

Metafold jobs endpoint.

get(id: str) Job

Get a job.

Parameters:

id – ID of job to get.

Returns:

Job resource.

list(sort: str | None = None, q: str | None = None) list[Job]

List jobs.

Parameters:
  • sort – Sort string. For details on syntax see the Metafold API docs. Supported sorting fields are: “id”, “name”, or “created”.

  • q – Query string. For details on syntax see the Metafold API docs. Supported search fields are: “id”, “name”, “type”, and “state”.

Returns:

List of job resources.

run(type: str, params: dict[str, Any], name: str | None = None, timeout: int | float = 120) Job

Dispatch a new job and wait for a result.

See Metafold API docs for the full list of jobs.

Parameters:
  • type – Job type.

  • params – Job parameters.

  • name – Optional job name.

  • timeout – Time in seconds to wait for a result.

Returns:

Completed job resource.

update(id: str, name: str | None = None) Job

Update a job.

Parameters:
  • id – ID of job to update.

  • name – New job name. The existing name remains unchanged if None.

Returns:

Updated job resource.

Module contents

class metafold.MetafoldClient(access_token: str, project_id: str, base_url: str = 'https://api.metafold3d.com')

Bases: Client

Metafold REST API client.

assets

Sub-client for assets endpoint.

jobs

Sub-client for jobs endpoint.