Projects.ImageStorage package

Submodules

Projects.ImageStorage.ContentSizeLimitMiddleware module

class Projects.ImageStorage.ContentSizeLimitMiddleware.ContentSizeLimitMiddleware(app: any, max_content_size: int)[source]

Bases: object

Content size limiting middleware for ASGI applications.

Parameters:
  • app (any) – ASGI application.

  • max_content_size (int) – The maximum content size allowed in bytes.

receive_wrapper(receive)[source]

Projects.ImageStorage.ImageStorageCli module

class Projects.ImageStorage.ImageStorageCli.ImageStorageCli(host: str, port: int, url_path: str = '')[source]

Bases: object

A class to interact with the ImageStorage API.

host

address of the API.

Type:

str

port

Port of API.

Type:

int

url_path

URL path of the API.

Type:

str

url

The full URL of the API.

Type:

str

Create the image storage client.

Parameters:
  • host (str) – Address of the API.

  • port (int) – Port of the API.

  • url_path (str, optional) – URL path of the API. Defaults to “”.

download(image_id: str) Image[source]

Download an image from the image storage.

Parameters:

image_id (str) – The ID of the image to download.

Raises:

Exception – If the request fails.

Returns:

The downloaded image object.

Return type:

Structures.Image.Image

upload_bytes(image_bytes: bytes, name: str, file_type: str, source: str = '', purpose: str = '') str[source]

Upload an image bytes to the image storage.

Parameters:
  • image_bytes (bytes) – The image bytes.

  • name (str) – The filename of the image.

  • file_type (str) – The MIME type of the image.

  • source (str, optional) – Optional source of the image. Defaults to “”.

  • purpose (str, optional) – Optional purpose of the image. Defaults to “”.

Raises:

requests.exceptions.HTTPError – If the request fails.

Returns:

The ID of the uploaded image.

Return type:

str

upload_file(path: str | Path, source: str = '', purpose: str = '') str[source]

Upload an image file to the image storage.

Parameters:
  • path (Union[str, Path]) – Path to an image file.

  • source (str, optional) – Optional source of the image. Defaults to “”.

  • purpose (str, optional) – Optional purpose of the image. Defaults to “”.

Returns:

The ID of the uploaded image.

Return type:

str

upload_image(image: ndarray, file_name: str = 'image.png', source: str = '', purpose: str = '') str[source]

Upload a numpy image to the image storage.

Parameters:
  • image (np.ndarray) – The numpy image to upload.

  • file_name (str, optional) – File name of the image that will be created. Defaults to “image.png”.

  • source (str, optional) – Optional source of the image. Defaults to “”.

  • purpose (str, optional) – Optional purpose of the image. Defaults to “”.

Returns:

The ID of the uploaded image.

Return type:

str

visualize(entity_ids: List[str], visualization_params: dict = {}) str[source]

Create a visualization of the given entity IDs.

Parameters:
  • entity_ids (List[str]) – List of entity IDs to visualize.

  • visualization_params (dict, optional) – Visualization parameters. Defaults to {}.

Raises:

requests.exceptions.HTTPError – If the request fails.

Returns:

ID of the generated image.

Return type:

str

Projects.ImageStorage.Storage module

class Projects.ImageStorage.Storage.File(path: Path)[source]

Bases: object

class Projects.ImageStorage.Storage.Storage(config: dict)[source]

Bases: object

Manage a local file storage and update its state in a context broker.

Create a Storage object.

Parameters:

config (dict) – Configuration dict.

add_file(path: Path, data_model: Type[BaseModel] | None = None, key: str | None = None)[source]

Add an existing file.

Parameters:
  • path (Path) – Path to the file.

  • data_model (Optional[Type[BaseModel]]) – A data model object representing the file to upload to the context broker. If None, no data model will be uploaded to the context broker. Defaults to None.

  • key (Optional[str]) – Optional key to use if no data model is provided, otherwise is ignored. Defaults to None.

Raises:
  • ValueError – If key already exists or it is None.

  • FileNotFoundError – If file does not exist.

check_dir_limits()[source]

Check the limits of the storage dir.

check_files_time()[source]

Check the maximum time of the files.

delete_all()[source]

Delete all the inserted file.

delete_file(key: str)[source]

Delete a file permanently.

Parameters:

key (str) – The file key.

get_file_path(filename: str) Path[source]

Get the storage file path from a filename.

Parameters:

filename (str) –

Returns:

Path

initialize()[source]

Initialize the file record with the files already present on the storage path.

keys() List[str][source]

Return an ordered list with the file keys in insertion order.

property path: Path

Returns the storage path.

property total_size: int

Return the total size of the stored files.

Projects.ImageStorage.api module

class Projects.ImageStorage.api.ImageStorage(config: dict)[source]

Bases: object

API to upload and download images, keeping a reference to the file in a context broker. It also allows the creation of data models visualization images.

Start the api server.

Parameters:

config (dict) – Configuration dict.

TITLE = 'Image Storage API'
VERSION = '0.2.2'
Projects.ImageStorage.api.main()[source]

Module contents