Patrons

The client.patrons sub-client contains methods for interacting with patron-related endpoints in the Libib API.

This page documents the available patron methods, expected parameters, and example responses.


Error Format

All methods return a Python dict on failure in the following format:

{
    "status": "error",
    "code": response.status_code,
    "body": response.json(),
}

Get Patrons

Retrieve a list of all existing patrons on your site.

  • Returns 50 patrons per request
  • Supports pagination
  • This client automatically handles pagination when retrieving more than 50 patrons

For lists of patrons greater than 50, this method automatically handles pagination (with a 2 second pause between calls).

Example

patrons = client.patrons.get_patrons()

Returns (Success)

[
    {
        "barcode": "2020000000013",
        "first_name": "Mary",
        "last_name": "Shelley",
        "email": "frankenstein@example.com",
        "notification_emails": None,
        "tags": None,
        "patron_id": "mshelley",
        "address1": None,
        "phone": "555-123-4567",
        "address2": None,
        "city": "Augusta",
        "state": "KS",
        "country": "US",
        "zip": None,
        "freeze": None,
    },
    {
        "barcode": "2020000000037",
        "first_name": "Marcus",
        "last_name": "Aurelius",
        "email": "meditations@example.com",
        "notification_emails": None,
        "tags": None,
        "patron_id": None,
        "phone": None,
        "address1": None,
        "address2": None,
        "city": None,
        "state": None,
        "country": "US",
        "zip": None,
        "freeze": 1,
    },
]

Get Patron By ID

Retrieve a single patron by passing the patron's barcode or email.

Parameters

  • identifier (str): The patron's barcode or email.

Example (Using email)

patron = client.patrons.get_patron_by_id("frankenstein@example.com")

Example (Using barcode)

patron = client.patrons.get_patron_by_id("2020000000013")

Returns (Success)

{
    "barcode": "2020000000013",
    "first_name": "Mary",
    "last_name": "Shelley",
    "email": "frankenstein@example.com",
    "notification_emails": None,
    "tags": None,
    "patron_id": "mshelley",
    "phone": "555-123-4567",
    "address1": None,
    "address2": None,
    "city": "Augusta",
    "state": "KS",
    "country": "US",
    "zip": None,
    "freeze": None,
}

Create a Patron

Create a new patron in your Libib account.

Supported Parameters

You may pass any number of the following keyword arguments:

[
    "barcode",
    "first_name",
    "last_name",
    "email",
    "notification_emails",
    "tags",
    "patron_id",
    "phone",
    "address1",
    "address2",
    "city",
    "state",
    "country",
    "zip",
    "freeze",
    "password",
]

Libib recommends not setting the barcode field manually.

Example

created = client.patrons.create_patron(
    email="frankenstein@example.com",
    first_name="Mary",
    last_name="Shelley",
    patron_id="mshelley",
)

Returns (Success)

True

Update a Patron

Update one or more fields for an existing patron.

Pass the patron's barcode or email as the id.

Parameters

  • identifier (str): The patron's barcode or email.

Supported Update Fields

You may pass any number of the following keyword arguments:

[
    "barcode",
    "first_name",
    "last_name",
    "email",
    "notification_emails",
    "tags",
    "patron_id",
    "phone",
    "address1",
    "address2",
    "city",
    "state",
    "country",
    "zip",
    "freeze",
    "password",
]

Libib recommends not updating the barcode field.

Example

updated = client.patrons.update_patron(
    id="frankenstein@example.com",
    first_name="Mary",
    last_name="Shelley",
    patron_id="mshelley",
)

Returns (Success)

True

Restore a Patron

Restore a previously deleted patron.

Patrons can be restored within 30 days of deletion.

Parameters

  • identifier (str): The patron's barcode or email.

Example (Using barcode)

restored = client.patrons.restore_patron("2020000000013")

Example (Using email)

restored = client.patrons.restore_patron("frankenstein@example.com")

Returns (Success)

True

Delete a Patron

Delete a patron by barcode or email.

Deleting a patron dissociates their lending and hold history.

Parameters

  • identifier (str): The patron's barcode or email.

Example (Using barcode)

deleted = client.patrons.delete_patron("2020000000013")

Example (Using email)

deleted = client.patrons.delete_patron("frankenstein@example.com")

Returns (Success)

True