omnipy.components.remote.tasks
Tasks for fetching remote resources and building URL datasets.
| CLASS | DESCRIPTION |
|---|---|
GithubRepoContext |
Describe a GitHub repository location used for URL generation. |
| FUNCTION | DESCRIPTION |
|---|---|
async_get_github_repo_urls |
Asynchronously create raw GitHub content URLs for repository files. |
async_load_urls_into_new_dataset |
Asynchronously load remote URLs into a newly created dataset instance. |
get_auto_from_api_endpoint |
Fetch an API endpoint and decode the response from its MIME type. |
get_bytes_from_api_endpoint |
Fetch an API endpoint and decode the response body as raw bytes. |
get_github_repo_urls |
Create raw GitHub content URLs for one file or matching files in a repository path. |
get_json_from_api_endpoint |
Fetch a JSON API endpoint and decode the response body as JSON. |
get_retry_client |
Build a retry-enabled HTTP client wrapper. |
get_str_from_api_endpoint |
Fetch an API endpoint and decode the response body as text. |
load_urls_into_new_dataset |
Load remote URLs into a newly created dataset instance. |
GithubRepoContext
dataclass
Describe a GitHub repository location used for URL generation.
| PARAMETER | DESCRIPTION |
|---|---|
owner
|
GitHub repository owner or organization.
TYPE:
|
repo
|
Repository name.
TYPE:
|
branch
|
Branch or reference to read from.
TYPE:
|
path
|
File or directory path inside the repository.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
GithubRepoContext
|
Repository context container. |
| RAISES | DESCRIPTION |
|---|---|
TypeError
|
If field values do not match declared types. |
Example
ctx = GithubRepoContext('octocat', 'hello-world', 'main', 'docs') ctx.repo 'hello-world'
| METHOD | DESCRIPTION |
|---|---|
__init__ |
|
| ATTRIBUTE | DESCRIPTION |
|---|---|
branch |
TYPE:
|
owner |
TYPE:
|
path |
TYPE:
|
repo |
TYPE:
|
Source code in src/omnipy/components/remote/tasks.py
async_get_github_repo_urls
async
async_get_github_repo_urls(
owner: str, repo: str, branch: str, path: str | Path, file_suffix: str | None = None
) -> HttpUrlDataset
Asynchronously create raw GitHub content URLs for repository files.
| PARAMETER | DESCRIPTION |
|---|---|
owner
|
GitHub repository owner or organization.
TYPE:
|
repo
|
Repository name.
TYPE:
|
branch
|
Branch or ref to read from.
TYPE:
|
path
|
File or directory path inside the repository.
TYPE:
|
file_suffix
|
Optional suffix filter when
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
HttpUrlDataset
|
A dataset of raw-content URLs keyed by file name. |
| RAISES | DESCRIPTION |
|---|---|
TypeError
|
If any input cannot be converted to expected model types. |
Example
urls = await async_get_github_repo_urls('octocat', 'hello-world', 'main', 'README.md')
isinstance(urls, HttpUrlDataset)
True
Source code in src/omnipy/components/remote/tasks.py
async_load_urls_into_new_dataset
async
async_load_urls_into_new_dataset(
urls: HttpUrlDataset,
dataset_cls: type[_JsonDatasetT] = JsonDataset,
as_mime_type: str | None = None,
) -> _JsonDatasetT
Asynchronously load remote URLs into a newly created dataset instance.
| PARAMETER | DESCRIPTION |
|---|---|
urls
|
Dataset containing the URLs to load.
TYPE:
|
dataset_cls
|
Dataset type to populate from the fetched content.
TYPE:
|
as_mime_type
|
Optional MIME type override for response decoding.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
_JsonDatasetT
|
A newly loaded dataset of type |
| RAISES | DESCRIPTION |
|---|---|
TypeError
|
If fetched data cannot be parsed by |
Example
loaded = await async_load_urls_into_new_dataset(
HttpUrlDataset({'a': 'https://example.com'}),
)
isinstance(loaded, JsonDataset)
True
Source code in src/omnipy/components/remote/tasks.py
get_auto_from_api_endpoint
async
get_auto_from_api_endpoint(
url: HttpUrlModel, retry_client: RetryClient | None = None, as_mime_type: str | None = None
) -> AutoResponseContentModel
Fetch an API endpoint and decode the response from its MIME type.
| PARAMETER | DESCRIPTION |
|---|---|
url
|
HTTP URL to request.
TYPE:
|
client_session
|
Optional shared aiohttp client session.
|
retry_http_statuses
|
HTTP status codes that trigger retries.
|
retry_attempts
|
Maximum number of retry attempts.
|
retry_backoff_strategy
|
Backoff policy used between retries.
|
as_mime_type
|
Optional MIME type override for response decoding.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
AutoResponseContentModel
|
The response content wrapped together with its effective content type. |
| RAISES | DESCRIPTION |
|---|---|
AssertionError
|
If the response has no |
ConnectionError
|
If the endpoint response status is not |
Example
data = await get_auto_from_api_endpoint(HttpUrlModel('https://example.com/data'))
isinstance(data, AutoResponseContentModel)
True
Source code in src/omnipy/components/remote/tasks.py
get_bytes_from_api_endpoint
async
get_bytes_from_api_endpoint(
url: HttpUrlModel, retry_client: RetryClient | None = None
) -> BytesModel
Fetch an API endpoint and decode the response body as raw bytes.
| PARAMETER | DESCRIPTION |
|---|---|
url
|
HTTP URL to request.
TYPE:
|
client_session
|
Optional shared aiohttp client session.
|
retry_http_statuses
|
HTTP status codes that trigger retries.
|
retry_attempts
|
Maximum number of retry attempts.
|
retry_backoff_strategy
|
Backoff policy used between retries.
|
| RETURNS | DESCRIPTION |
|---|---|
BytesModel
|
The response body as bytes. |
| RAISES | DESCRIPTION |
|---|---|
ConnectionError
|
If the endpoint response status is not |
Example
blob = await get_bytes_from_api_endpoint(HttpUrlModel('https://example.com/file'))
isinstance(blob, BytesModel)
True
Source code in src/omnipy/components/remote/tasks.py
get_github_repo_urls
get_github_repo_urls(
owner: str, repo: str, branch: str, path: str | Path, file_suffix: str | None = None
) -> HttpUrlDataset
Create raw GitHub content URLs for one file or matching files in a repository path.
| PARAMETER | DESCRIPTION |
|---|---|
owner
|
GitHub repository owner or organization.
TYPE:
|
repo
|
Repository name.
TYPE:
|
branch
|
Branch or ref to read from.
TYPE:
|
path
|
File or directory path inside the repository.
TYPE:
|
file_suffix
|
Optional suffix filter when
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
HttpUrlDataset
|
A dataset of raw-content URLs keyed by file name. |
| RAISES | DESCRIPTION |
|---|---|
TypeError
|
If any input cannot be converted to expected model types. |
Example
urls = get_github_repo_urls('octocat', 'hello-world', 'main', 'README.md')
isinstance(urls, HttpUrlDataset)
True
Source code in src/omnipy/components/remote/tasks.py
get_json_from_api_endpoint
async
get_json_from_api_endpoint(url: HttpUrlModel, retry_client: RetryClient | None = None) -> JsonModel
Fetch a JSON API endpoint and decode the response body as JSON.
| PARAMETER | DESCRIPTION |
|---|---|
url
|
HTTP URL to request.
TYPE:
|
client_session
|
Optional shared aiohttp client session.
|
retry_http_statuses
|
HTTP status codes that trigger retries.
|
retry_attempts
|
Maximum number of retry attempts.
|
retry_backoff_strategy
|
Backoff policy used between retries.
|
| RETURNS | DESCRIPTION |
|---|---|
JsonModel
|
The decoded JSON response for the requested URL. |
| RAISES | DESCRIPTION |
|---|---|
ConnectionError
|
If the endpoint response status is not |
ValueError
|
If the response body cannot be decoded as JSON. |
Example
result = await get_json_from_api_endpoint(HttpUrlModel('https://api.example.com'))
isinstance(result, JsonModel)
True
Source code in src/omnipy/components/remote/tasks.py
get_retry_client
get_retry_client(
client_session: ClientSession | None = None,
retry_http_statuses: tuple[int, ...] = DEFAULT_RETRY_STATUSES,
retry_attempts: int = DEFAULT_RETRIES,
retry_backoff_strategy: BackoffStrategy.Literals = DEFAULT_BACKOFF_STRATEGY,
) -> RetryClient
Build a retry-enabled HTTP client wrapper.
| PARAMETER | DESCRIPTION |
|---|---|
client_session
|
Existing client session to wrap.
TYPE:
|
retry_http_statuses
|
Status codes that should trigger retries.
TYPE:
|
retry_attempts
|
Maximum number of retry attempts.
TYPE:
|
retry_backoff_strategy
|
Backoff strategy identifier.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
RetryClient
|
Configured retry client instance.
TYPE:
|
| RAISES | DESCRIPTION |
|---|---|
KeyError
|
If |
Example
retry_client = _get_retry_client(session, (429, 503), 5, 'exponential')
type(retry_client).name
'RetryClient'
Source code in src/omnipy/components/remote/tasks.py
get_str_from_api_endpoint
async
get_str_from_api_endpoint(url: HttpUrlModel, retry_client: RetryClient | None = None) -> StrModel
Fetch an API endpoint and decode the response body as text.
| PARAMETER | DESCRIPTION |
|---|---|
url
|
HTTP URL to request.
TYPE:
|
client_session
|
Optional shared aiohttp client session.
|
retry_http_statuses
|
HTTP status codes that trigger retries.
|
retry_attempts
|
Maximum number of retry attempts.
|
retry_backoff_strategy
|
Backoff policy used between retries.
|
| RETURNS | DESCRIPTION |
|---|---|
StrModel
|
The response body as plain text. |
| RAISES | DESCRIPTION |
|---|---|
ConnectionError
|
If the endpoint response status is not |
Example
text = await get_str_from_api_endpoint(HttpUrlModel('https://example.com'))
isinstance(text, StrModel)
True
Source code in src/omnipy/components/remote/tasks.py
load_urls_into_new_dataset
load_urls_into_new_dataset(
urls: HttpUrlDataset,
dataset_cls: type[_JsonDatasetT] = JsonDataset,
as_mime_type: str | None = None,
) -> _JsonDatasetT
Load remote URLs into a newly created dataset instance.
| PARAMETER | DESCRIPTION |
|---|---|
urls
|
Dataset containing the URLs to load.
TYPE:
|
dataset_cls
|
Dataset type to populate from the fetched content.
TYPE:
|
as_mime_type
|
Optional MIME type override for response decoding.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
_JsonDatasetT
|
A newly loaded dataset of type |
| RAISES | DESCRIPTION |
|---|---|
TypeError
|
If fetched data cannot be parsed by |
Example
loaded = load_urls_into_new_dataset(HttpUrlDataset({'a': 'https://example.com'}))
isinstance(loaded, JsonDataset)
True