Skip to content

Pricings

albert.collections.pricings

InventoryId module-attribute

InventoryId = Annotated[
    str, AfterValidator(ensure_inventory_id)
]

AlbertSession

AlbertSession(
    *,
    base_url: str,
    token: str | None = None,
    auth_manager: AlbertClientCredentials
    | AlbertSSOClient
    | None = None,
    retries: int | None = None,
)

Bases: Session

A session that has a base URL, which is prefixed to all request URLs.

Parameters:

Name Type Description Default
base_url str

The base URL to prefix to all relative request paths (e.g., "https://app.albertinvent.com").

required
token str | None

A static JWT token for authentication. Ignored if auth_manager is provided.

None
auth_manager AlbertClientCredentials | AlbertSSOClient

An authentication manager used to dynamically fetch and refresh tokens. If provided, it overrides token.

None
retries int

The number of automatic retries on failed requests (default is 3).

None

Methods:

Name Description
request
Source code in src/albert/core/session.py
def __init__(
    self,
    *,
    base_url: str,
    token: str | None = None,
    auth_manager: AlbertClientCredentials | AlbertSSOClient | None = None,
    retries: int | None = None,
):
    super().__init__()
    self.base_url = base_url
    self.headers.update(
        {
            "Content-Type": "application/json",
            "Accept": "application/json",
            "User-Agent": f"albert-SDK V.{albert.__version__}",
        }
    )

    if token is None and auth_manager is None:
        raise ValueError("Either `token` or `auth_manager` must be specified.")

    self._auth_manager = auth_manager
    self._provided_token = token

    # Set up retry logic
    retries = retries if retries is not None else 3
    retry = Retry(
        total=retries,
        read=retries,
        connect=retries,
        backoff_factor=0.3,
        status_forcelist=(500, 502, 503, 504, 403),
        raise_on_status=False,
    )
    adapter = HTTPAdapter(max_retries=retry)
    self.mount("http://", adapter)
    self.mount("https://", adapter)

base_url instance-attribute

base_url = base_url

request

request(
    method: str, path: str, *args, **kwargs
) -> Response
Source code in src/albert/core/session.py
def request(self, method: str, path: str, *args, **kwargs) -> requests.Response:
    self.headers["Authorization"] = f"Bearer {self._access_token}"
    full_url = urljoin(self.base_url, path) if not path.startswith("http") else path
    with handle_http_errors():
        response = super().request(method, full_url, *args, **kwargs)
        response.raise_for_status()
        return response

BaseCollection

BaseCollection(*, session: AlbertSession)

BaseCollection is the base class for all collection classes.

Parameters:

Name Type Description Default
session AlbertSession

The Albert API Session instance.

required
Source code in src/albert/collections/base.py
def __init__(self, *, session: AlbertSession):
    self.session = session

session instance-attribute

session = session

InventoryPricings pydantic-model

Bases: BaseAlbertModel

Pricings for a given InventoryItem.

Attributes:

Name Type Description
inventory_id Inventory

The inventory ID the pricings belong to.

pricings list[Pricing]

The list of pricings.

Show JSON schema:
{
  "$defs": {
    "AuditFields": {
      "description": "The audit fields for a resource",
      "properties": {
        "by": {
          "default": null,
          "title": "By",
          "type": "string"
        },
        "byName": {
          "anyOf": [
            {
              "type": "string"
            },
            {
              "type": "null"
            }
          ],
          "default": null,
          "title": "Byname"
        },
        "at": {
          "anyOf": [
            {
              "format": "date-time",
              "type": "string"
            },
            {
              "type": "null"
            }
          ],
          "default": null,
          "title": "At"
        }
      },
      "title": "AuditFields",
      "type": "object"
    },
    "Company": {
      "description": "Company is a Pydantic model representing a company entity.\n\nAttributes\n----------\nname : str\n    The name of the company.\nid : str | None\n    The Albert ID of the company. Set when the company is retrieved from Albert.\ndistance : float | None\n    The scores of a company in a search result, optional. Read-only.",
      "properties": {
        "status": {
          "anyOf": [
            {
              "$ref": "#/$defs/Status"
            },
            {
              "type": "null"
            }
          ],
          "default": null
        },
        "Created": {
          "anyOf": [
            {
              "$ref": "#/$defs/AuditFields"
            },
            {
              "type": "null"
            }
          ],
          "default": null
        },
        "Updated": {
          "anyOf": [
            {
              "$ref": "#/$defs/AuditFields"
            },
            {
              "type": "null"
            }
          ],
          "default": null
        },
        "name": {
          "title": "Name",
          "type": "string"
        },
        "albertId": {
          "anyOf": [
            {
              "type": "string"
            },
            {
              "type": "null"
            }
          ],
          "default": null,
          "title": "Albertid"
        },
        "distance": {
          "anyOf": [
            {
              "type": "number"
            },
            {
              "type": "null"
            }
          ],
          "default": null,
          "title": "Distance"
        }
      },
      "required": [
        "name"
      ],
      "title": "Company",
      "type": "object"
    },
    "EntityLink": {
      "properties": {
        "id": {
          "title": "Id",
          "type": "string"
        },
        "name": {
          "anyOf": [
            {
              "type": "string"
            },
            {
              "type": "null"
            }
          ],
          "default": null,
          "title": "Name"
        }
      },
      "required": [
        "id"
      ],
      "title": "EntityLink",
      "type": "object"
    },
    "LeadTimeUnit": {
      "description": "The unit of measure for the provided lead time.",
      "enum": [
        "Days",
        "Weeks",
        "Months"
      ],
      "title": "LeadTimeUnit",
      "type": "string"
    },
    "Location": {
      "description": "A location in Albert.\n\nAttributes\n----------\nname : str\n    The name of the location.\nid : str | None\n    The Albert ID of the location. Set when the location is retrieved from Albert.\nlatitude : float\n    The latitude of the location.\nlongitude : float\n    The longitude of the location.\naddress : str\n    The address of the location.\ncountry : str | None\n    The country code of the location. Must be two characters long.",
      "properties": {
        "status": {
          "anyOf": [
            {
              "$ref": "#/$defs/Status"
            },
            {
              "type": "null"
            }
          ],
          "default": null
        },
        "Created": {
          "anyOf": [
            {
              "$ref": "#/$defs/AuditFields"
            },
            {
              "type": "null"
            }
          ],
          "default": null
        },
        "Updated": {
          "anyOf": [
            {
              "$ref": "#/$defs/AuditFields"
            },
            {
              "type": "null"
            }
          ],
          "default": null
        },
        "name": {
          "title": "Name",
          "type": "string"
        },
        "albertId": {
          "anyOf": [
            {
              "type": "string"
            },
            {
              "type": "null"
            }
          ],
          "default": null,
          "title": "Albertid"
        },
        "latitude": {
          "title": "Latitude",
          "type": "number"
        },
        "longitude": {
          "title": "Longitude",
          "type": "number"
        },
        "address": {
          "title": "Address",
          "type": "string"
        },
        "country": {
          "anyOf": [
            {
              "maxLength": 2,
              "minLength": 2,
              "type": "string"
            },
            {
              "type": "null"
            }
          ],
          "default": null,
          "title": "Country"
        }
      },
      "required": [
        "name",
        "latitude",
        "longitude",
        "address"
      ],
      "title": "Location",
      "type": "object"
    },
    "Pricing": {
      "description": "A Price of a given InventoryItem at a given Location.\n\nAttributes\n----------\nid : str | None\n    The Albert ID of the pricing. Set when the pricing is retrieved from Albert.\ninventory_id : str\n    The Albert ID of the inventory item.\ncompany : Company\n    The company that the pricing belongs to.\nlocation : Location\n    The location that the pricing belongs to.\ndescription : str | None\n    The description of the pricing. Optional.\npack_size : str | None\n    The pack size of the pricing. Optional. Used to calculate the cost per unit.\nprice : float\n    The price of the pricing IN CURRENCY/ KG or CURRENCY/L! Must do the conversion! Depends on InventoryItem's unit of measure.\ncurrency : str\n    The currency of the pricing. Defaults to `USD`.\nfob : str | None\n    The FOB of the pricing. Optional.\nlead_time : int | None\n    The lead time of the pricing. Optional.\nlead_time_unit : LeadTimeUnit | None\n    The unit of measure for the provided lead time. Optional.\nexpiration_date : str | None\n    The expiration date of the pricing. YYYY-MM-DD format.",
      "properties": {
        "status": {
          "anyOf": [
            {
              "$ref": "#/$defs/Status"
            },
            {
              "type": "null"
            }
          ],
          "default": null
        },
        "Created": {
          "anyOf": [
            {
              "$ref": "#/$defs/AuditFields"
            },
            {
              "type": "null"
            }
          ],
          "default": null
        },
        "Updated": {
          "anyOf": [
            {
              "$ref": "#/$defs/AuditFields"
            },
            {
              "type": "null"
            }
          ],
          "default": null
        },
        "albertId": {
          "anyOf": [
            {
              "type": "string"
            },
            {
              "type": "null"
            }
          ],
          "default": null,
          "title": "Albertid"
        },
        "parentId": {
          "anyOf": [
            {
              "type": "string"
            },
            {
              "type": "null"
            }
          ],
          "default": null,
          "title": "Parentid"
        },
        "Company": {
          "anyOf": [
            {
              "$ref": "#/$defs/Company"
            },
            {
              "$ref": "#/$defs/EntityLink"
            }
          ],
          "title": "Company"
        },
        "Location": {
          "anyOf": [
            {
              "$ref": "#/$defs/Location"
            },
            {
              "$ref": "#/$defs/EntityLink"
            }
          ],
          "title": "Location"
        },
        "description": {
          "anyOf": [
            {
              "type": "string"
            },
            {
              "type": "null"
            }
          ],
          "default": null,
          "title": "Description"
        },
        "packSize": {
          "anyOf": [
            {
              "type": "string"
            },
            {
              "type": "null"
            }
          ],
          "default": null,
          "title": "Packsize"
        },
        "price": {
          "maximum": 9999999999,
          "minimum": 0,
          "title": "Price",
          "type": "number"
        },
        "currency": {
          "default": "USD",
          "title": "Currency",
          "type": "string"
        },
        "fob": {
          "anyOf": [
            {
              "type": "string"
            },
            {
              "type": "null"
            }
          ],
          "default": null,
          "title": "Fob"
        },
        "leadTime": {
          "anyOf": [
            {
              "type": "integer"
            },
            {
              "type": "null"
            }
          ],
          "default": null,
          "title": "Leadtime"
        },
        "leadTimeUnit": {
          "anyOf": [
            {
              "$ref": "#/$defs/LeadTimeUnit"
            },
            {
              "type": "null"
            }
          ],
          "default": null
        },
        "expirationDate": {
          "anyOf": [
            {
              "type": "string"
            },
            {
              "type": "null"
            }
          ],
          "default": null,
          "title": "Expirationdate"
        },
        "default": {
          "anyOf": [
            {
              "type": "integer"
            },
            {
              "type": "null"
            }
          ],
          "default": null,
          "title": "Default"
        }
      },
      "required": [
        "Company",
        "Location",
        "price"
      ],
      "title": "Pricing",
      "type": "object"
    },
    "Status": {
      "description": "The status of a resource",
      "enum": [
        "active",
        "inactive"
      ],
      "title": "Status",
      "type": "string"
    }
  },
  "description": "Pricings for a given InventoryItem.\n\nAttributes\n----------\ninventory_id : Inventory\n    The inventory ID the pricings belong to.\npricings : list[Pricing]\n    The list of pricings.",
  "properties": {
    "id": {
      "title": "Id",
      "type": "string"
    },
    "pricings": {
      "items": {
        "$ref": "#/$defs/Pricing"
      },
      "title": "Pricings",
      "type": "array"
    }
  },
  "required": [
    "id",
    "pricings"
  ],
  "title": "InventoryPricings",
  "type": "object"
}

Fields:

inventory_id pydantic-field

inventory_id: InventoryId

pricings pydantic-field

pricings: list[Pricing]

OrderBy

Bases: str, Enum

ASCENDING class-attribute instance-attribute

ASCENDING = 'asc'

DESCENDING class-attribute instance-attribute

DESCENDING = 'desc'

Pricing

Bases: BaseResource

A Price of a given InventoryItem at a given Location.

Attributes:

Name Type Description
id str | None

The Albert ID of the pricing. Set when the pricing is retrieved from Albert.

inventory_id str

The Albert ID of the inventory item.

company Company

The company that the pricing belongs to.

location Location

The location that the pricing belongs to.

description str | None

The description of the pricing. Optional.

pack_size str | None

The pack size of the pricing. Optional. Used to calculate the cost per unit.

price float

The price of the pricing IN CURRENCY/ KG or CURRENCY/L! Must do the conversion! Depends on InventoryItem's unit of measure.

currency str

The currency of the pricing. Defaults to USD.

fob str | None

The FOB of the pricing. Optional.

lead_time int | None

The lead time of the pricing. Optional.

lead_time_unit LeadTimeUnit | None

The unit of measure for the provided lead time. Optional.

expiration_date str | None

The expiration date of the pricing. YYYY-MM-DD format.

company class-attribute instance-attribute

company: SerializeAsEntityLink[Company] = Field(
    alias="Company"
)

currency class-attribute instance-attribute

currency: str = Field(default='USD', alias='currency')

default class-attribute instance-attribute

default: int | None = Field(
    default=None, exclude=True, frozen=True
)

description class-attribute instance-attribute

description: str | None = Field(default=None)

expiration_date class-attribute instance-attribute

expiration_date: str | None = Field(
    default=None, alias="expirationDate"
)

fob class-attribute instance-attribute

fob: str | None = Field(default=None)

id class-attribute instance-attribute

id: str | None = Field(default=None, alias='albertId')

inventory_id class-attribute instance-attribute

inventory_id: str | None = Field(
    default=None, alias="parentId"
)

lead_time class-attribute instance-attribute

lead_time: int | None = Field(
    default=None, alias="leadTime"
)

lead_time_unit class-attribute instance-attribute

lead_time_unit: LeadTimeUnit | None = Field(
    default=None, alias="leadTimeUnit"
)

location class-attribute instance-attribute

location: SerializeAsEntityLink[Location] = Field(
    alias="Location"
)

pack_size class-attribute instance-attribute

pack_size: str | None = Field(
    default=None, alias="packSize"
)

price class-attribute instance-attribute

price: float = Field(ge=0, le=9999999999)

PricingBy

Bases: str, Enum

COMPANY class-attribute instance-attribute

COMPANY = 'Company'

LOCATION class-attribute instance-attribute

LOCATION = 'Location'

PricingCollection

PricingCollection(*, session: AlbertSession)

Bases: BaseCollection

PricingCollection is a collection class for managing Pricing entities in the Albert platform.

Parameters:

Name Type Description Default
session AlbertSession

The Albert session instance.

required

Methods:

Name Description
create

Creates a new Pricing entity.

delete

Deletes a Pricing entity by its ID.

get_by_id

Retrieves a Pricing entity by its ID.

get_by_inventory_id

Returns a list of Pricing entities for the given inventory ID as per the provided parameters.

get_by_inventory_ids

Returns a list of Pricing resources for each parent inventory ID.

update

Updates a Pricing entity.

Source code in src/albert/collections/pricings.py
def __init__(self, *, session: AlbertSession):
    """Initializes the PricingCollection with the provided session.

    Parameters
    ----------
    session : AlbertSession
        The Albert session instance.
    """
    super().__init__(session=session)
    self.base_path = f"/api/{PricingCollection._api_version}/pricings"

base_path instance-attribute

base_path = f'/api/{_api_version}/pricings'

create

create(*, pricing: Pricing) -> Pricing

Creates a new Pricing entity.

Parameters:

Name Type Description Default
pricing Pricing

The Pricing entity to create.

required

Returns:

Type Description
Pricing

The created Pricing entity.

Source code in src/albert/collections/pricings.py
def create(self, *, pricing: Pricing) -> Pricing:
    """Creates a new Pricing entity.

    Parameters
    ----------
    pricing : Pricing
        The Pricing entity to create.

    Returns
    -------
    Pricing
        The created Pricing entity.
    """
    payload = pricing.model_dump(by_alias=True, exclude_none=True, mode="json")
    response = self.session.post(self.base_path, json=payload)
    return Pricing(**response.json())

delete

delete(*, id: str) -> None

Deletes a Pricing entity by its ID.

Parameters:

Name Type Description Default
id str

The ID of the Pricing entity to delete.

required
Source code in src/albert/collections/pricings.py
def delete(self, *, id: str) -> None:
    """Deletes a Pricing entity by its ID.

    Parameters
    ----------
    id : str
        The ID of the Pricing entity to delete.
    """
    url = f"{self.base_path}/{id}"
    self.session.delete(url)

get_by_id

get_by_id(*, id: str) -> Pricing

Retrieves a Pricing entity by its ID.

Parameters:

Name Type Description Default
id str

The ID of the Pricing entity to retrieve.

required

Returns:

Type Description
Pricing

The Pricing entity if found, None otherwise.

Source code in src/albert/collections/pricings.py
def get_by_id(self, *, id: str) -> Pricing:
    """Retrieves a Pricing entity by its ID.

    Parameters
    ----------
    id : str
        The ID of the Pricing entity to retrieve.

    Returns
    -------
    Pricing
        The Pricing entity if found, None otherwise.
    """
    url = f"{self.base_path}/{id}"
    response = self.session.get(url)
    return Pricing(**response.json())

get_by_inventory_id

get_by_inventory_id(
    *,
    inventory_id: str,
    group_by: PricingBy | None = None,
    filter_by: PricingBy | None = None,
    filter_id: str | None = None,
    order_by: OrderBy | None = None,
) -> list[Pricing]

Returns a list of Pricing entities for the given inventory ID as per the provided parameters.

Parameters:

Name Type Description Default
inventory_id str

The ID of the inventory to retrieve pricings for.

required
group_by PricingBy | None

Grouping by PricingBy, by default None

None
filter_by PricingBy | None

Filter by PricingBy, by default None

None
filter_id str | None

The string to use as the filter, by default None

None
order_by OrderBy | None

The order to sort the results by, by default None

None

Returns:

Type Description
list[Pricing]

A list of Pricing entities matching the provided parameters.

Source code in src/albert/collections/pricings.py
def get_by_inventory_id(
    self,
    *,
    inventory_id: str,
    group_by: PricingBy | None = None,
    filter_by: PricingBy | None = None,
    filter_id: str | None = None,
    order_by: OrderBy | None = None,
) -> list[Pricing]:
    """Returns a list of Pricing entities for the given inventory ID as per the provided parameters.

    Parameters
    ----------
    inventory_id : str
        The ID of the inventory to retrieve pricings for.
    group_by : PricingBy | None, optional
        Grouping by PricingBy, by default None
    filter_by : PricingBy | None, optional
        Filter by PricingBy, by default None
    filter_id : str | None, optional
        The string to use as the filter, by default None
    order_by : OrderBy | None, optional
        The order to sort the results by, by default None

    Returns
    -------
    list[Pricing]
        A list of Pricing entities matching the provided parameters.
    """
    params = {
        "parentId": inventory_id,
        "groupBy": group_by,
        "filterBy": filter_by,
        "id": filter_id,
        "orderBy": order_by,
    }
    params = {k: v for k, v in params.items() if v is not None}
    response = self.session.get(self.base_path, params=params)
    items = response.json().get("Items", [])
    return [Pricing(**x) for x in items]

get_by_inventory_ids

get_by_inventory_ids(
    *, inventory_ids: list[InventoryId]
) -> list[InventoryPricings]

Returns a list of Pricing resources for each parent inventory ID.

Parameters:

Name Type Description Default
inventory_ids list[str]

The list of inventory IDs to retrieve pricings for.

required

Returns:

Type Description
list[InventoryPricing]

A list of InventoryPricing objects matching the provided inventory.

Source code in src/albert/collections/pricings.py
@validate_call
def get_by_inventory_ids(self, *, inventory_ids: list[InventoryId]) -> list[InventoryPricings]:
    """Returns a list of Pricing resources for each parent inventory ID.

    Parameters
    ----------
    inventory_ids : list[str]
        The list of inventory IDs to retrieve pricings for.

    Returns
    -------
    list[InventoryPricing]
        A list of InventoryPricing objects matching the provided inventory.
    """
    params = {"id": inventory_ids}
    response = self.session.get(f"{self.base_path}/ids", params=params)
    return [InventoryPricings(**x) for x in response.json()["Items"]]

update

update(*, pricing: Pricing) -> Pricing

Updates a Pricing entity.

Parameters:

Name Type Description Default
pricing Pricing

The updated Pricing entity.

required

Returns:

Type Description
Pricing

The updated Pricing entity as it appears in Albert.

Source code in src/albert/collections/pricings.py
def update(self, *, pricing: Pricing) -> Pricing:
    """Updates a Pricing entity.

    Parameters
    ----------
    pricing : Pricing
        The updated Pricing entity.

    Returns
    -------
    Pricing
        The updated Pricing entity as it appears in Albert.
    """
    current_pricing = self.get_by_id(id=pricing.id)
    patch_payload = self._pricing_patch_payload(existing=current_pricing, updated=pricing)
    self.session.patch(
        url=f"{self.base_path}/{pricing.id}",
        json=patch_payload.model_dump(mode="json", by_alias=True),
    )
    return self.get_by_id(id=pricing.id)