model¶

Base model implementation for Short.io API objects.

This module provides the foundational data models for the Short.io API client library, implementing common patterns for representing and interacting with Short.io resources. The models follow three key design patterns:

  1. Raw Data Storage Pattern:

All models store the original API response data in a _data attribute, treating the API response schema as potentially unstable. Properties provide a stable interface for accessing the underlying data, making the code more resilient to API changes.

  1. Property-Based Access Pattern:

All attributes are exposed through properties rather than direct instance attributes. This approach allows for lazy loading, data validation, and type conversion while maintaining a clean public interface.

  1. Core Data Extraction Pattern:

Each model implements a core_data property that returns a standardized, minimal representation of the object. This provides a consistent way to access essential information across different model types.

These models are designed to be instantiated by the API client methods, not directly by users of the library. They provide a Pythonic interface to the JSON data returned by the Short.io API.

class pyshortio.model.BaseModel[source]¶

Base class for all Short.io API object models.

This abstract base class provides common functionality for data validation, parameter handling, and consistent interfaces across all Short.io resource models. It implements parameter validation for required fields and provides methods to distinguish between required and optional parameters.

All Short.io API resource models (Domain, Link, Folder, etc.) inherit from this class, ensuring consistent behavior and interfaces throughout the library.

The class works with the sentinel values (REQ, NA) defined in the arg module to manage required vs. optional fields in a dataclass-friendly way.

property core_data: Dict[str, Any]¶

Returns a dictionary containing the essential data of the model.

This property must be implemented by all subclasses to provide a consistent minimal representation of the model’s core data.

class pyshortio.model.Domain(_data: dict[str, Any] = _REQUIRED())[source]¶

Domain model representing a Short.io domain configuration.

This class provides a Pythonic interface to Short.io domain data while maintaining access to the raw API response through the _data attribute. All domain properties are accessed through getter methods that retrieve values from the underlying data.

Following the Raw Data Storage Pattern, the Domain model doesn’t define its own attributes beyond _data, instead exposing all API data through property methods.

Ref:

property core_data: Dict[str, Any]¶

Returns a dictionary containing the essential data of the model.

This property must be implemented by all subclasses to provide a consistent minimal representation of the model’s core data.

Link model representing a Short.io shortened URL.

This class provides a comprehensive Pythonic interface to Short.io link data while preserving access to the raw API response. The Link model implements the Raw Data Storage Pattern, storing the original API response in the _data attribute and accessing it through property methods.

All link properties are accessed through getter methods that retrieve values from the underlying data dictionary, providing resilience against API schema changes. This approach treats the Short.io API response as having an unstable schema, storing raw values as-is and using lazy-loaded properties to access the data instead of defining them as instance attributes.

Property methods handle type conversion (e.g., converting string dates to datetime objects) and gracefully handle missing values by returning None for optional fields.

Note

All properties return None if the corresponding data is not present in the raw API response, providing safe access to optional fields.

Ref:

property core_data: Dict[str, Any]¶

Get the essential link data in a simplified dictionary.

class pyshortio.model.Folder(_data: dict[str, Any] = _REQUIRED())[source]¶

Folder model representing a Short.io link organization folder.

This class provides access to folder data from the Short.io API. Following the same pattern as other models, it stores the raw API response in the _data attribute and provides property methods for accessing specific attributes.

property core_data: Dict[str, Any]¶

Returns a dictionary containing the essential data of the model.

This property must be implemented by all subclasses to provide a consistent minimal representation of the model’s core data.