Skip to content

cmem_client.models.item¤

ImportItem base class and inherited classes

A marketplace package can be installed from a directory, a single file or a zip archive. These classes hide that difference: create_import_item() picks the right one for a path, and using it as a context manager yields a directory the import can read from, extracting the archive first where that is needed and cleaning up after.

Classes:

  • DirectoryImportItem – Import from a directory - no transformation needed.
  • FileImportItem – Import from a single file, copy to temp directory.
  • ImportItem – Abstract base class for different import source types.
  • ZipImportItem – Import from a zip archive - extract to temp directory.

Functions:

DirectoryImportItem¤

Bases: ImportItem

Import from a directory - no transformation needed.

Functions:

  • cleanup – No cleanup needed for directories.
  • detect – Detect the appropriate ImportItem type for the given source.
  • prepare – Return directory path as-is.

Attributes:

cleanup¤

cleanup()

No cleanup needed for directories.

detect¤

detect(source)

Detect the appropriate ImportItem type for the given source.

Parameters:

  • source (Path) – Path to analyze

Returns:

  • type[ImportItem] – The appropriate ImportItem subclass

import_type¤

import_type = 'directory'

model_config¤

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

prepare¤

prepare()

Return directory path as-is.

source¤

source = Path(source) if isinstance(source, str) else source

FileImportItem¤

Bases: ImportItem

Import from a single file, copy to temp directory.

Functions:

  • cleanup – Remove temporary directory.
  • detect – Detect the appropriate ImportItem type for the given source.
  • prepare – Copy file to a temporary directory.

Attributes:

cleanup¤

cleanup()

Remove temporary directory.

detect¤

detect(source)

Detect the appropriate ImportItem type for the given source.

Parameters:

  • source (Path) – Path to analyze

Returns:

  • type[ImportItem] – The appropriate ImportItem subclass

import_type¤

import_type = 'file'

model_config¤

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

prepare¤

prepare()

Copy file to a temporary directory.

source¤

source = Path(source) if isinstance(source, str) else source

ImportItem¤

ImportItem(source)

Bases: ABC, Model

Abstract base class for different import source types.

Each concrete implementation represents a different source type (file, directory, zip, etc.) and knows how to prepare itself for import by providing a Path to a directory or file.

Attributes:

  • import_type (str) – Name of the source type this class handles, one of directory, file or zip.
  • source – Path the import reads from, as passed to the constructor.

Functions:

  • cleanup – Clean up any temporary resources created during preparation.
  • detect – Detect the appropriate ImportItem type for the given source.
  • prepare – Prepare the import source and return a path to import from.

Parameters:

  • source (Path | str) – Source path or identifier for the import

cleanup¤

cleanup()

Clean up any temporary resources created during preparation.

detect¤

detect(source)

Detect the appropriate ImportItem type for the given source.

Parameters:

  • source (Path) – Path to analyze

Returns:

  • type[ImportItem] – The appropriate ImportItem subclass

import_type¤

import_type: str

model_config¤

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

prepare¤

prepare()

Prepare the import source and return a path to import from.

This method transforms the source into a format suitable for import. For example:

  • Zip files are extracted to a temp directory
  • Directories are returned as-is

Returns:

  • Path – Path to directory or file ready for import

source¤

source = Path(source) if isinstance(source, str) else source

ZipImportItem¤

ZipImportItem(source)

Bases: ImportItem

Import from a zip archive - extract to temp directory.

Functions:

  • cleanup – Remove temporary directory.
  • detect – Detect the appropriate ImportItem type for the given source.
  • prepare – Extract zip to temporary directory.

Attributes:

cleanup¤

cleanup()

Remove temporary directory.

detect¤

detect(source)

Detect the appropriate ImportItem type for the given source.

Parameters:

  • source (Path) – Path to analyze

Returns:

  • type[ImportItem] – The appropriate ImportItem subclass

import_type¤

import_type = 'zip'

model_config¤

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

prepare¤

prepare()

Extract zip to temporary directory.

source¤

source = Path(source) if isinstance(source, str) else source

create_import_item¤

create_import_item(source)

Factory function to create appropriate ImportItem instance.

Parameters:

  • source (Path) – Path to the import source

Returns:

  • ImportItem – Appropriate ImportItem instance based on source type

Comments