Skip to main content

Python wrappers for working with the Sierra ILS

Project description

sierra-ils-utils

sierra-ils-utils is a Python library / wrapper around HTTPX -- providing largely the same fully featured HTTP client for Python 3).

The library provides convenient synchronous and asynchronous methods for working with the Sierra ILS REST API. The client provided by the library automatically handles the token-based authentication (client-credentials flow) and includes configurable retry and backoff logic.


Installation

# You can install sierra-ils-utils from PyPI:
pip install sierra-ils-utils

Quick Start

from sierra_ils_utils import SierraAPI

client = SierraRESTClient(
    base_url="https://catalog.library.org/iii/sierra-api/v6/",
    client_id="YOUR_CLIENT_ID",
    client_secret="YOUR_CLIENT_SECRET"
)

# Make a synchronous request (returns a httpx.Response)
response = client.request("GET", "info/token")  # <Response [200 200]>
response.raise_for_status()

# Or, make an async request (returns a httpx.Response)
response = await client.async_request("GET", "info/token")  # <Response [200 200]>
response.raise_for_status()

The request() and async_request() client methods will return httpx.Response objects.

Other Utilities

SierraDateTime and SierraDate

Some Sierra REST API endpoints expect dates and times in a specific ISO8601-like format. The library provides two helpers:

  1. SierraDateTime: A thin wrapper around Python’s datetime, ensuring:

    • timezone-aware date / datetime creation -- defaulting to UTC
    • microseconds removed
    • output in ISO 8601 format ending with Z (e.g. 2020-07-07T12:55:00Z)
  2. SierraDate: A thin wrapper around Python's date, ensuring:

    • output is in YYYY-MM-DD format

Example Usage:

from sierra_ils_utils import SierraDateTime
from datetime import timedelta

# generate a current timestamp for use with the REST API
datetime_now  = SierraDateTime.now()
print(datetime_now)  # 2025-01-30T19:31:43Z

# SierraDateTime is a `datetime` object, so you can use `timedelta` with it
datetime_prev = datetime_now - timedelta(days=1)
print(datetime_prev)  # 2025-01-29T19:31:43Z

# date ranges in Sierra REST API look like this:
# [2025-01-27T19:21:59Z,2025-01-30T19:21:59Z]
range_string = f"[{datetime_prev},{datetime_now}]"

# Get a list of items created in the last 1 day
response = client.request(
    'GET',
    'items/',
    params={
        'createdDate': range_string,  # using the range from above
        'limit': 2000
    }
)
response.raise_for_status()  # handle errors

print(response.json().get('total', 0))  # 1664
# You can also use timezones to create dates that are in your local timezone ...
first_monday_2025 = SierraDateTime.from_string(
  '2025-01-06 00:00:00', 'America/New_York'
)
print(first_monday_2025)  # 2025-01-06T05:00:00Z

License

This project is released under the MIT License.

Authors

Ray Voelker – ray.voelker@gmail.com

Issues and Support

Please open an issue on GitHub if you encounter problems, bugs, or have feature requests. We welcome all contributions and feedback!

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

sierra_ils_utils-0.0.1a20250130.tar.gz (10.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

sierra_ils_utils-0.0.1a20250130-py3-none-any.whl (8.0 kB view details)

Uploaded Python 3

File details

Details for the file sierra_ils_utils-0.0.1a20250130.tar.gz.

File metadata

File hashes

Hashes for sierra_ils_utils-0.0.1a20250130.tar.gz
Algorithm Hash digest
SHA256 7594b8a77fe8b9c52ae1ae6cff8736ffeddec2300bc7ca9012a91c38b64a0f5a
MD5 cd5f8e50b09d9ec6afd1359e9bf85772
BLAKE2b-256 d232abb80156a700185fe5a99f15a9a3c1af733e181984394dfd03890a836ec3

See more details on using hashes here.

File details

Details for the file sierra_ils_utils-0.0.1a20250130-py3-none-any.whl.

File metadata

File hashes

Hashes for sierra_ils_utils-0.0.1a20250130-py3-none-any.whl
Algorithm Hash digest
SHA256 e7fa3398470e94d24ce37568e0aeae070a805cf1b267d99c0a0f6111f7c18a57
MD5 d1aba931576177efb144dcdb5654bba3
BLAKE2b-256 d9fa6d25d8db414803b7e31345fa64a1bef4fbe6acabb05522f23563a5e331b1

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page