# Getting Started with the ERMLib Python SDK

> A hands-on guide to the ERMLib Python SDK: installation, authentication, common operations and patterns for robust library automation scripts.

- Source: https://ermlib.com/en/updates/ermlib-sdk-python-guide
- Publisher: Horato & Co Ltd
- Published: 2026-10-14
- Category: Technical Deep Dives
- Tags: Python, SDK, developer, automation, scripting, API

The ERMLib Python SDK makes it straightforward to interact with your library system programmatically. Whether you are building custom reports, automating workflows, or integrating ERMLib with other campus systems, the SDK handles authentication, request formatting, and error handling so you can focus on your application logic.

## Installation

The SDK is available on PyPI and supports Python 3.9 and above.

```
pip install ermlib-sdk
```

## Authentication

Every SDK operation requires authentication. The simplest approach for server-side scripts is to use client credentials.

```python
from ermlib import ErmLibClient

client = ErmLibClient(
    base_url="https://your-institution.ermlib.com",
    client_id="your-client-id",
    client_secret="your-client-secret",
)
```

The client handles token refresh automatically. For applications that act on behalf of individual users, the SDK also supports OAuth 2.0 authorization code flow.

## Working With Records

Searching the catalog is one of the most common SDK operations. The search method accepts keyword queries, fielded searches, and filter parameters.

```python
results = client.catalog.search(
    query="machine learning",
    filters={"format": "book", "language": "eng"},
    limit=25,
)

for record in results.items:
    print(f"{record.title} ({record.publication_year})")
```

Retrieving a specific record by its identifier returns the full metadata along with availability information.

```python
record = client.catalog.get("bib-12345")
print(record.subjects)
print(record.available_copies)
```

## Patron Operations

The patron module provides access to account information, borrowing history, and hold management. All patron operations require appropriate API permissions.

```python
patron = client.patrons.get("patron-67890")

for loan in patron.active_loans:
    print(f"{loan.title} — due {loan.due_date}")
```

Placing a hold is a single method call.

```python
hold = client.circulation.place_hold(
    patron_id="patron-67890",
    record_id="bib-12345",
    pickup_location="main-library",
)
```

## Batch Operations

For bulk updates, the SDK supports batch requests that process up to 100 operations in a single API call. This is significantly more efficient than making individual requests in a loop.

```python
operations = [
    {"action": "update", "record_id": "bib-001", "fields": {"status": "withdrawn"}},
    {"action": "update", "record_id": "bib-002", "fields": {"status": "withdrawn"}},
]

results = client.catalog.batch(operations)
print(f"Processed {results.successful} of {results.total}")
```

## Error Handling

The SDK raises typed exceptions for common error conditions. Wrapping calls in try-except blocks lets you handle failures gracefully.

```python
from ermlib.exceptions import NotFoundError, RateLimitError

try:
    record = client.catalog.get("bib-99999")
except NotFoundError:
    print("Record not found")
except RateLimitError as e:
    print(f"Rate limited. Retry after {e.retry_after} seconds")
```

## What to Build

Our community has built some creative tools with the SDK: automated weeding reports that flag low-circulation items, Slack bots that notify staff when high-priority holds are filled, scripts that sync course reserve lists from the LMS, and dashboards that aggregate statistics across branch locations.

The full SDK documentation, including additional code examples and a changelog, is available at `docs.ermlib.com/sdk/python`. We welcome contributions and feedback through the SDK's GitHub repository.
