cmeta.utils.net module

Network functions

cMeta author and developer: (C) 2025-2026 Grigori Fursin

See the cMeta COPYRIGHT and LICENSE files in the project root for details.

Functions

cmeta.utils.net.access_api(url: str, params: dict, headers: dict = {}, timeout: int = 30)[source]

Send POST request to FastAPI endpoint with JSON params and return response.

Parameters:
  • url (str) – The API endpoint URL.

  • params (dict) – Dictionary of parameters to send as JSON in the POST request body.

  • headers (dict) – Optional dictionary of HTTP headers to include in the request.

  • timeout (int) – Request timeout in seconds. Default is 30 seconds.

Returns:

Dictionary with ‘return’: 0 and ‘response’ containing parsed JSON response,

or ‘return’: 1 and ‘error’ message on failure.

Return type:

dict

cmeta.utils.net.download(url: str, filename: str | None = None, path: str | None = None, chunk_size: int = 65536, show_progress: bool = False, fail_on_error: bool = False, text: str = 'Downloading ')[source]

Download a file from URL to local filesystem.

Auto-detects filename from URL if not provided. Supports progress display with tqdm if show_progress is enabled.

Parameters:
  • url (str) – URL of the file to download.

  • filename (str | None) – Name for the downloaded file. If None, extracts from URL.

  • path (str | None) – Directory to save the file. If None, uses current working directory.

  • chunk_size (int) – Size of chunks to download in bytes. Default is 65536 (64KB).

  • show_progress (bool) – If True, displays download progress using tqdm.

  • fail_on_error (bool) – If True, raises exception on error instead of returning error dict.

  • text (str) – Prefix text for progress bar description.

Returns:

Dictionary with ‘return’: 0, ‘filename’, ‘path’, and ‘size’ on success,

or ‘return’: 1 and ‘error’ on failure.

Return type:

dict

async cmeta.utils.net.unify_request(request)[source]