๐Ÿ”Œ Application Programming Interface#

galactic.helpers.market.core module.

class Market#

Bases: Cache

Singleton class representing a market of proxies managing cached packages.

__init__()#

Initialize the Market instance.

static __new__(cls)#

Create a singleton instance of the Market class.

Return type:

Market

add_proxy(proxy)#

Add a new proxy to the market.

Parameters:

proxy (Proxy) โ€“ The Proxy instance to add.

Raises:
  • TypeError โ€“ If proxy is not an instance of Proxy.

  • ValueError โ€“ If a proxy with the same name or url already exists.

Return type:

None

get_proxy(name)#

Get a proxy by its name.

Parameters:

name (str) โ€“ The name of the proxy to retrieve.

Returns:

The Proxy instance with the specified name.

Return type:

Proxy

Raises:
load_proxy(name)#

Load the proxy by downloading the latest packages from the remote index.

Raises:

RuntimeError โ€“ If the download fails for any package.

Return type:

None

property proxies: list[Proxy]#

Get the list of proxies managed by the market.

Returns:

A list of Proxy instances managed by the market.

Return type:

list[Proxy]

remove_proxy(name)#

Remove a proxy by its name.

Parameters:

name (str) โ€“ The name of the proxy to remove.

Raises:
Return type:

None

save_proxy(name)#

Save the proxy metadata to the proxies.json file.

Parameters:

name (str) โ€“ The name of the proxy to save.

Raises:
Return type:

None

unload_proxy(name)#

Unload the proxy by removing its cached packages.

Parameters:

name (str) โ€“ The name of the proxy to unload.

Raises:

TypeError โ€“ If name is not a string.

Return type:

None

unsave_proxy(name)#

Remove the proxy metadata from the proxies.json file.

Parameters:

name (str) โ€“ The name of the proxy to remove.

Raises:
Return type:

None

class Proxy(name, summary, url, is_system=False, created_at=None, loaded_at=None, package_count=None, access_level=None)#

Bases: object

Class representing a proxy for managing Python package repositories.

property access_level: str#

Get the access level of the proxy.

Returns:

The access level of the proxy.

Return type:

str

property created_at: datetime#

Get the timestamp when the proxy was created.

Returns:

The creation timestamp in ISO 8601 format.

Return type:

datetime

fetch_access_level()#

Determine the access level of the proxy by performing an HTTP GET request.

Returns:

One of the following access levels: - โ€œpublicโ€: accessible without authentication (HTTP 200) - โ€œprotectedโ€: requires authentication but is free (HTTP 401) - โ€œpaidโ€: requires payment for access (HTTP 402) - โ€œprivateโ€: requires special permissions (HTTP 403) - โ€œnetwork_errorโ€: if a network error occurs

Return type:

str

fetch_package_count()#

Get the number of packages available in the proxy.

Returns:

The number of packages in the proxy, or -1 if an error occurs.

Return type:

int

property is_system: bool#

Check if the proxy is a system-level proxy.

Returns:

True if the proxy is system-level, False otherwise.

Return type:

bool

property loaded_at: datetime#

Get the timestamp when the proxy was last updated.

Returns:

The last updated timestamp in ISO 8601 format.

Return type:

datetime

property name: str#

Get the proxyโ€™s name.

Returns:

The name of the proxy.

Return type:

str

property package_count: int#

Get the number of packages available in the proxy.

Returns:

The number of packages in the proxy.

Return type:

int

property summary: str#

Get the proxyโ€™s summary description.

Returns:

The summary text.

Return type:

str

property url: str#

Get the proxyโ€™s URL.

Returns:

The URL of the proxy.

Return type:

str

class Cache#

Bases: object

Utility class for managing cached Python packages.

static find_matching_packages(**criteria)#

Find packages in the cache matching given criteria.

Parameters:

criteria (dict) โ€“ A dictionary of criteria to match against package metadata.

Returns:

A list of metadata dictionaries for each matching package.

Return type:

list[dict[str, str]]

Raises:

TypeError โ€“ If criteria is not a dictionary or contains invalid keys.

static get_package(name)#

Find package metadata by name using fuzzy matching.

Parameters:

name (str) โ€“ The name of the package to search for (without version).

Returns:

Metadata dictionary of the closest matching package.

Return type:

dict[str, str]

Raises:

FileNotFoundError โ€“ If no matching package is found in the cache.

static get_packages()#

List all wheel packages grouped by proxy folder.

Returns:

Mapping proxy folder name -> list of package metadata dicts.

Return type:

dict[str, list[dict[str, str]]]

Raises:

FileNotFoundError โ€“ If the cache directory does not exist or is not a directory.

static get_proxy_packages(name)#

List all wheel packages for a given proxy name.

Parameters:

name (str) โ€“ The name of the proxy (used as folder name in cache).

Returns:

A list of metadata dictionaries for each wheel file.

Return type:

list[dict[str, str]]

static install_package(name, extra_index_urls=None)#

Install a package by name using fuzzy matching.

Parameters:
  • name (str) โ€“ The name of the package to install (without version).

  • extra_index_urls (list[str] | None, optional) โ€“ Additional PyPI index URLs to use during installation.

Returns:

The name of the installed package file.

Return type:

str

Raises:
static purge_cache()#

Purge the entire cache directory by removing it and recreating it.

Return type:

None

static purge_config()#

Purge the configuration directory by removing it and recreating it.

Return type:

None