redshred.microservices package

Submodules

redshred.microservices.generic module

class redshred.microservices.generic.Microservice(api: redshred.api.http.RedShredAPI, endpoint: str = None, params: dict = NOTHING)[source]

Bases: object

A base class representing a generic microservice for interacting with external APIs.

This class is designed to serve as a template for accessing services provided by a microservice architecture. It allows for configuration of the API endpoint, parameters to be sent with the request, and provides a convenient callable interface that abstracts away the details of making HTTP requests.

Attributes:

api (RedShredAPI): An instance of RedShredAPI that provides methods for making API requests. endpoint (str, optional): The specific service endpoint to target within the microservice. params (dict): A dictionary of default parameters to include with every request made by the instance.

Methods:
__call__(collection: Union[“Collection”, str], **params) -> Any:

Makes a call to the configured microservice endpoint with the given parameters. Optionally accepts a collection object or slug, preparing the appropriate request path and combining any additional parameters with the default ones.

If a regions parameter is provided and it is a GeoJSON object, it will be converted to its JSON representation before being sent with the request.

Raises:

HTTPError: If the underlying API call returns a response with an error status code.

api: redshred.api.http.RedShredAPI
endpoint: str
params: dict

redshred.microservices.segment_cropper module

class redshred.microservices.segment_cropper.SegmentCropper(api, **kwargs)[source]

Bases: Microservice

Provides functionality to crop segments of data by a specified region.

This microservice is specialized for cropping images based on geographic regions provided in the form of GeoJSON or a segment ID.

Inherits from a more generic Microservice class.

Args:

api: the RedShredAPI object used to use to communicate with the RedShred API. **kwargs: Arbitrary keyword arguments passed along to the Microservice base class.

api: redshred.api.http.RedShredAPI
endpoint: str
get_crop(collection: 'Collection' | str, regions: 'GeoJSON' | str, **params)[source]

Retrieves a cropped image of the provided regions/segment.

This method sends a request to the associated microservice API to perform the crop operation and return the result.

Args:

collection: A Collection instance or a string representing the data collection to be cropped. regions: A GeoJSON object or a string representing the geographic regions by which to crop

the image from.

**params: Arbitrary keyword arguments representing additional parameters for the crop operation.

Returns:

The content of the response from the microservice API after performing the crop operation, which is bytes representing the cropped image.

params: dict

redshred.microservices.token_lookup module

class redshred.microservices.token_lookup.TokenLookup(api, **kwargs)[source]

Bases: Microservice

A microservice that allows you to extract text for any given RedShred segment.

This microservice is specialized for extracting text based on geographic regions provided in the form of GeoJSON or a segment ID.

Inherits from a more generic Microservice class.

Args:

api: The RedShredAPI object used to communicate with the RedShred API. **kwargs: Arbitrary keyword arguments passed along to the Microservice base class.

api: redshred.api.http.RedShredAPI
endpoint: str
get_text(collection: 'Collection' | str, regions: 'GeoJSON' | str, **params)[source]

Retrieves the text of the provided regions/segment.

This method sends a request to the associated microservice API to perform the text extraction operation and return the result.

Args:

collection: A Collection instance or a string representing the data collection to be cropped. regions: A GeoJSON object or a string representing the geographic regions by which to extract

the text from.

**params: Arbitrary keyword arguments representing additional parameters for the text extraction operation.

Returns:

The content of the response from the microservice API after performing the text extraction operation, which is a string representing the extracted text.

params: dict

Module contents