Skip to content

cmem_client.repositories.marketplace_packages¤

Repository for the marketplace packages installed in Corporate Memory.

Provides MarketplacePackagesRepository for installing packages from an archive or directory, exporting an installed package again and removing one. The packages available on a marketplace server are offered by the Marketplace component (client.marketplace) instead.

Examples:

List the installed packages:

>>> from cmem_client.client import Client
>>> client = Client.from_env()
>>> list(client.marketplace_packages)

Install a package archive and export an installed package:

>>> from pathlib import Path
>>> from cmem_client.repositories.marketplace_packages import (
...     MarketplacePackagesExportConfig,
...     MarketplacePackagesImportConfig,
... )
>>> from cmem_client.repositories.protocols.import_item import ImportConflictPolicy
>>> client.marketplace_packages.import_item(
...     key="w3c-geo-vocab",
...     configuration=MarketplacePackagesImportConfig(install_from_marketplace=True),
...     on_conflict=ImportConflictPolicy.REPLACE
... )
>>> client.marketplace_packages.export_item(
...     key="w3c-geo-vocab",
...     path=Path("w3c-geo-vocab"),
...     configuration=MarketplacePackagesExportConfig(export_as_zip=False),
... )
>>> client.marketplace_packages.delete_item(key="w3c-geo-vocab", skip_if_missing=True)

Classes:

Functions:

Attributes:

LOCK_FILE_RESOURCE¤

LOCK_FILE_RESOURCE = f'{MARKETPLACE_PROJECT_ID}:mp-lock.json'

MAX_DEPENDENCY_DEPTH¤

MAX_DEPENDENCY_DEPTH = 5

MarketplacePackagesDeleteConfig¤

Bases: DeleteConfig

Package deletion configuration

Attributes:

  • skip_missing_dependencies (bool) – If True, dependencies which are not installed are skipped instead of raising an error.
  • skip_missing_graphs (bool) – If True, graphs of the package which do not exist are skipped instead of raising an error.
  • skip_missing_projects (bool) – If True, projects of the package which do not exist are skipped instead of raising an error.
  • ignore_lock (bool) – If set to True, ignore the lock mechanism.
  • ignore_dependencies (bool) – If True, dependencies of the package are not deleted.
  • dependency_level (int) – Current recursion depth for dependency resolution. Used internally to identify the top-level call. Should not be set manually.

dependency_level¤

dependency_level: int = 0

ignore_dependencies¤

ignore_dependencies: bool = False

ignore_lock¤

ignore_lock: bool = False

model_config¤

model_config = ConfigDict(extra='allow', populate_by_name=True)

skip_missing_dependencies¤

skip_missing_dependencies: bool = True

skip_missing_graphs¤

skip_missing_graphs: bool = True

skip_missing_projects¤

skip_missing_projects: bool = True

MarketplacePackagesExportConfig¤

Bases: ExportConfig

Package export configuration

Attributes:

  • export_graph_serialization (Literal[‘turtle’, ‘pretty-turtle’]) – Graph export serialization format.
  • export_as_zip (bool) – If true, export the package as a zip file, otherwise as a directory.

export_as_zip¤

export_as_zip: bool = True

export_graph_serialization¤

export_graph_serialization: LiteralType['turtle', 'pretty-turtle'] = 'pretty-turtle'

model_config¤

model_config = ConfigDict(extra='allow', populate_by_name=True)

MarketplacePackagesImportConfig¤

Bases: ImportConfig

Configuration for marketplace package import operations.

Attributes:

  • ignore_dependencies (bool) – If True, skips installation of package dependencies.
  • install_from_marketplace (bool) – If True, downloads packages from the marketplace server. If False, loads packages from local filesystem.
  • package_version (PackageVersionIdentifier | None) – Specific version to install. If None, installs the latest version.
  • dependency_level (int) – Current recursion depth for dependency resolution. Used internally to prevent infinite recursion. Should not be set manually.
  • use_cache (bool) – Weather to use the cache directory to look packages up which have already been downloaded. To prevent the cache entirely, set this up in the marketplace component.
  • ignore_lock (bool) – If set to True, ignore the lock mechanism.

dependency_level¤

dependency_level: int = 0

ignore_dependencies¤

ignore_dependencies: bool = False

ignore_lock¤

ignore_lock: bool = False

install_from_marketplace¤

install_from_marketplace: bool = True

model_config¤

model_config = ConfigDict(extra='allow', populate_by_name=True)

package_version¤

package_version: PackageVersionIdentifier | None = None

use_archive_handler¤

use_archive_handler: bool = True

use_cache¤

use_cache: bool = True

MarketplacePackagesRepository¤

Bases: Repository, ImportItemProtocol, ExportItemProtocol, DeleteItemProtocol

Repository for marketplace package operations.

Functions:

  • delete_all – Delete all items from the repository
  • delete_item – Delete an item from the repository
  • export_item – Export an item from the repository to a file path.
  • fetch_data – Fetch installed packages from the package data graph via SPARQL query.
  • import_item – Import an exported file to the repository
  • items – Get the items of the repository
  • keys – Get the keys of the repository
  • values – Get the values of the repository

Attributes:

  • logger (Logger) – Gets the client logger

delete_all¤

delete_all()

Delete all items from the repository

delete_item¤

delete_item(key, skip_if_missing=False, configuration=None)

Delete an item from the repository

Parameters:

  • key (str) – The key of the item to delete
  • skip_if_missing (bool) – If True, it is ignored if the deleted item even exists
  • configuration (DeleteItemConfig) – Optional configuration for deletion

Raises:

export_item¤

export_item(key, path=None, replace=False, configuration=None)

Export an item from the repository to a file path.

Parameters:

  • key (str) – The key identifying the item to export.
  • path (Path | None) – The target file path for export. If None, a path will be generated.
  • replace (bool) – Whether to replace existing files at the target path.
  • configuration (ExportItemConfig_contra | None) – Optional configuration for export behavior.

Returns:

  • Path – The actual path where the item was exported.

Raises:

fetch_data¤

fetch_data()

Fetch installed packages from the package data graph via SPARQL query.

Queries the package data graph for all installed packages and their metadata.

import_item¤

import_item(path=None, key=None, on_conflict=ImportConflictPolicy.FAIL, configuration=None)

Import an exported file to the repository

By default, automatically handles zip files, directories, and single files using ImportItem model. Can be disabled by setting use_archive_handler=False in the configuration.

Returns:

  • str – The key of the imported item.

Raises:

  • RepositoryModificationError – If the item already exists and the conflict policy is FAIL, if the import type is not allowed for this repository, if the import request failed, or if the item is not present afterwards.

items¤

items()

Get the items of the repository

keys¤

keys()

Get the keys of the repository

logger¤

logger: logging.Logger

Gets the client logger

values¤

values()

Get the values of the repository

get_installation_metadata_query¤

get_installation_metadata_query(package_iri)

Get the query for the installation metadata of the package.

Comments