openconvert.client module

OpenConvert Client

Client class for connecting to the OpenConvert OpenAgents network, discovering conversion agents, and performing file conversions.

class openconvert.client.OpenConvertClient(agent_id=None)[source]

Bases: object

Client for interacting with the OpenConvert OpenAgents network.

Parameters:

agent_id (str | None)

__init__(agent_id=None)[source]

Initialize the OpenConvert client.

Parameters:

agent_id (str | None) – Optional agent ID. If not provided, a random one will be generated.

async connect(host='network.openconvert.ai', port=8765)[source]

Connect to the OpenConvert network.

Parameters:
  • host (str) – Network host to connect to

  • port (int) – Network port to connect to

Returns:

True if connection successful

Return type:

bool

async discover_agents(source_format, target_format)[source]

Discover agents capable of performing a specific conversion.

Parameters:
  • source_format (str) – Source MIME type

  • target_format (str) – Target MIME type

Returns:

List of agent information dictionaries

Return type:

List[Dict[str, Any]]

async convert_file(input_file, output_file, source_format, target_format, prompt=None, timeout=60)[source]

Convert a single file using the OpenConvert network.

Parameters:
  • input_file (Path) – Path to input file

  • output_file (Path) – Path to output file

  • source_format (str) – Source MIME type

  • target_format (str) – Target MIME type

  • prompt (str | None) – Optional conversion instructions

  • timeout (int) – Timeout in seconds for conversion

Returns:

True if conversion successful

Return type:

bool

async convert_files_batch(files, timeout=60)[source]

Convert multiple files in batch.

Parameters:
  • files (List[Dict[str, Any]]) – List of file conversion specifications, each containing: - input_file: Path to input file - output_file: Path to output file - source_format: Source MIME type - target_format: Target MIME type - prompt: Optional conversion prompt

  • timeout (int) – Timeout per file in seconds

Returns:

List of success flags for each conversion

Return type:

List[bool]

async list_available_conversions()[source]

Get a list of all available conversions in the network.

Returns:

Dictionary mapping source formats to lists of available target formats

Return type:

Dict[str, List[str]]

async disconnect()[source]

Disconnect from the OpenConvert network.

Return type:

None

async openconvert.client.convert_file(input_file, output_file, source_format=None, target_format=None, prompt=None, host='network.openconvert.ai', port=8765)[source]

Convenience function to convert a single file.

Parameters:
  • input_file (Path) – Path to input file

  • output_file (Path) – Path to output file

  • source_format (str | None) – Source MIME type (auto-detected if None)

  • target_format (str | None) – Target MIME type (auto-detected if None)

  • prompt (str | None) – Optional conversion instructions

  • host (str) – Network host

  • port (int) – Network port

Returns:

True if conversion successful

Return type:

bool

OpenConvertClient

class openconvert.client.OpenConvertClient(agent_id=None)[source]

Bases: object

Client for interacting with the OpenConvert OpenAgents network.

Parameters:

agent_id (str | None)

__init__(agent_id=None)[source]

Initialize the OpenConvert client.

Parameters:

agent_id (str | None) – Optional agent ID. If not provided, a random one will be generated.

async connect(host='network.openconvert.ai', port=8765)[source]

Connect to the OpenConvert network.

Parameters:
  • host (str) – Network host to connect to

  • port (int) – Network port to connect to

Returns:

True if connection successful

Return type:

bool

async discover_agents(source_format, target_format)[source]

Discover agents capable of performing a specific conversion.

Parameters:
  • source_format (str) – Source MIME type

  • target_format (str) – Target MIME type

Returns:

List of agent information dictionaries

Return type:

List[Dict[str, Any]]

async convert_file(input_file, output_file, source_format, target_format, prompt=None, timeout=60)[source]

Convert a single file using the OpenConvert network.

Parameters:
  • input_file (Path) – Path to input file

  • output_file (Path) – Path to output file

  • source_format (str) – Source MIME type

  • target_format (str) – Target MIME type

  • prompt (str | None) – Optional conversion instructions

  • timeout (int) – Timeout in seconds for conversion

Returns:

True if conversion successful

Return type:

bool

async convert_files_batch(files, timeout=60)[source]

Convert multiple files in batch.

Parameters:
  • files (List[Dict[str, Any]]) – List of file conversion specifications, each containing: - input_file: Path to input file - output_file: Path to output file - source_format: Source MIME type - target_format: Target MIME type - prompt: Optional conversion prompt

  • timeout (int) – Timeout per file in seconds

Returns:

List of success flags for each conversion

Return type:

List[bool]

async list_available_conversions()[source]

Get a list of all available conversions in the network.

Returns:

Dictionary mapping source formats to lists of available target formats

Return type:

Dict[str, List[str]]

async disconnect()[source]

Disconnect from the OpenConvert network.

Return type:

None