IzBib class

class almapiwrapper.inventory.IzBib(mms_id: str | None = None, zone: str | None = None, env: Literal['P', 'S'] | None = 'P', from_nz_mms_id: bool | None = False, copy_nz_rec: bool | None = False, data: XmlData | Element | None = None, create_bib: bool | None = False)

Bases: Bib

Class representing bibliographic record of the IZ

It inherits from Bib for common methods with NzBib.

Variables:
  • mms_id – record mms_id

  • zone – zone of the record

  • env – environment of the entity: ‘P’ for production and ‘S’ for sandbox

  • dataalmapiwrapper.record.XmlData object, useful to force update a record from a backup

  • error – True if the record encountered an error

  • parser – XML parser used for parsing responses

  • error_msg – stores the error message if an error occurred

  • area – ‘Bibs’

  • format – ‘xml’

  • api_base_url_bibs – Base URL of the bibs API

Parameters:
  • mms_id – MMS ID of the record (str)

  • zone – Zone of the record (str)

  • env – Environment of the entity: ‘P’ for production, ‘S’ for sandbox

  • data – Optional almapiwrapper.record.XmlData object, useful to force update a record from a backup

  • create_bib – if this parameter is True and no MMS ID is provided, a new IZ bib record is created

  • from_nz_mms_id – if this parameter is True the system assumes that the provided MMS ID is a network ID and fetch data from it

  • copy_nz_rec – if this parameter is True, if no record exists in the IZ for the provided NZ ID, the CZ record is copied from NZ

add_fields(self, fields: etree.Element | List[etree.Element]) 'Bib'

Add fields to the data of the current record

Parameters:

fields – must be an etree element or a list of etree elements

Returns:

almapiwrapper.inventory.Bib

Note

If the record encountered an error, this method will be skipped.

static api_call(method: Literal['get', 'put', 'post', 'delete'], *args, **kwargs) Response | None

Static method to handle http errors. Quit the program after 3 failed tries

Parameters:

method – ‘get’, ‘put’, ‘post’ or ‘delete’ according to the api method call

static build_headers(data_format: Literal['json', 'xml'], zone: str, area: str, rights: Literal['R', 'RW'] = 'RW', env: Literal['P', 'S'] | None = 'P') Dict

Build the headers for the API calls.

Parameters:
  • data_format – “json” or “xml”

  • zone – optional, if indicated allow to make the query in an other IZ

  • area – area of the record, bibs, users for example

  • rights – “R” for read only or “RW” for write and read rights

  • env – environment of the api call: ‘P’ for production, ‘S’ for sandbox

Returns:

dict with the headers

property data: Dict | Element | DataFrame | None

Property that get xml data with API call. If not available, make an api call

Returns:

xml data, dictionary or pandas dataframe

delete(force: bool = False) None

Delete bibliographic record in the IZ

To delete locally a record, it needs to be unlinked from the NZ and without holdings and items.

Parameters:

force – when True delete also holdings and items

Returns:

None

Note

If the record encountered an error, this method will be skipped.

delete_holdings(force: bool = False) None

Delete all holdings of the record with items if ‘force’ is True.

Parameters:

force – when True delete the items too.

Returns:

None

Note

If the record encountered an error, this method will be skipped.

static get_data_from_disk(mms_id: str, zone: str) XmlData | None

Fetch the data of the described record

Parameters:
  • mms_id – bib record mms_id

  • zone – zone of the record

Returns:

almapiwrapper.record.XmlData or None

get_holdings() List[Holding]

Get list of holdings and store it in ‘_holdings’ attribute

It avoids having to reload it.

Returns:

list of almapiwrapper.inventory.Holding objects

Note

If the record encountered an error, this method will be skipped.

get_local_fields(self) List[etree.Element]

Fetch the list of the local fields of the records

It looks for subfield “9” and then get the parent.

Returns:

list of etree.Element

Note

If the record encountered an error, this method will be skipped.

get_mms_id() str

Fetch the MMS ID from controlfield 001

Useful when fetching the bibliographic record with the NZ ID.

Returns:

str with MMS ID of 001 controlfield

Note

If the record encountered an error, this method will be skipped.

get_nz_mms_id(self) str | None

Fetch the NZ MMS ID of the IZ bib record

Returns:

string with NZ record MMS ID.

Note

If the record encountered an error, this method will be skipped.

static parse_data(data: JsonData | XmlData | Dict | str) JsonData | XmlData | None

Parse the data and return a parsed data object or None if an error occurs

Parameters:

data – data to be parsed

Returns:

parsed data object or None if an error occurs

save() Bib

Save a record in the ‘records’ folder

Versioning is supported. A suffix is added to the file path.

Example: records/NZ_991170519490005501/bib_991170519490005501_01.xml

Returns:

almapiwrapper.inventory.Bib

Note

If the record encountered an error, this method will be skipped.

sort_fields() Bib

Sort all the fields and subfields of the record

Returns:

Bib

Note

If the record encountered an error, this method will be skipped.

update() Bib

Update data

On IzBib records this method is used to change local fields. On NzBib records, other fields can be changed.

Returns:

almapiwrapper.inventory.Bib

Note

If the record encountered an error, this method will be skipped.

NzBib class

class almapiwrapper.inventory.NzBib(mms_id: str | None = None, env: Literal['P', 'S'] | None = 'P', data: XmlData | None = None, create_bib: bool = False)

Bases: Bib

Class representing a Network Zone (NZ) bibliographic record.

This class inherits from Bib and provides methods specific to NZ records, while sharing common functionality with IzBib.

Variables:
  • mms_id – MMS ID of the record

  • env – Environment of the entity (‘P’ for production, ‘S’ for sandbox)

  • dataalmapiwrapper.record.XmlData object, used to force update a record from a backup

  • error – True if the record encountered an error

  • parser – XML parser used for parsing responses

  • error_msg – stores the error message if an error occurred

  • area – ‘Bibs’

  • format – ‘xml’

  • api_base_url_bibs – Base URL of the bibs API

Parameters:
  • mms_id – MMS ID of the record (str)

  • env – Environment of the entity: ‘P’ for production, ‘S’ for sandbox

  • data – Optional almapiwrapper.record.XmlData object, useful to force update a record from a backup

  • create_bib – If True, creates a new bib record in the NZ

Example:
>>> nz_bib = NzBib(mms_id="991043825829705501", env="P")
>>> print(nz_bib.mms_id)
991043825829705501
add_fields(self, fields: etree.Element | List[etree.Element]) 'Bib'

Add fields to the data of the current record

Parameters:

fields – must be an etree element or a list of etree elements

Returns:

almapiwrapper.inventory.Bib

Note

If the record encountered an error, this method will be skipped.

static api_call(method: Literal['get', 'put', 'post', 'delete'], *args, **kwargs) Response | None

Static method to handle http errors. Quit the program after 3 failed tries

Parameters:

method – ‘get’, ‘put’, ‘post’ or ‘delete’ according to the api method call

static build_headers(data_format: Literal['json', 'xml'], zone: str, area: str, rights: Literal['R', 'RW'] = 'RW', env: Literal['P', 'S'] | None = 'P') Dict

Build the headers for the API calls.

Parameters:
  • data_format – “json” or “xml”

  • zone – optional, if indicated allow to make the query in an other IZ

  • area – area of the record, bibs, users for example

  • rights – “R” for read only or “RW” for write and read rights

  • env – environment of the api call: ‘P’ for production, ‘S’ for sandbox

Returns:

dict with the headers

property data: Dict | Element | DataFrame | None

Property that get xml data with API call. If not available, make an api call

Returns:

xml data, dictionary or pandas dataframe

delete(force: bool = False) None

Delete bibliographic record in the IZ

To delete locally a record, it needs to be unlinked from the NZ and without holdings and items.

Parameters:

force – when True delete also holdings and items

Returns:

None

Note

If the record encountered an error, this method will be skipped.

static get_data_from_disk(mms_id: str, zone: str) XmlData | None

Fetch the data of the described record

Parameters:
  • mms_id – bib record mms_id

  • zone – zone of the record

Returns:

almapiwrapper.record.XmlData or None

get_mms_id() str

Fetch the MMS ID from controlfield 001

Useful when fetching the bibliographic record with the NZ ID.

Returns:

str with MMS ID of 001 controlfield

Note

If the record encountered an error, this method will be skipped.

static parse_data(data: JsonData | XmlData | Dict | str) JsonData | XmlData | None

Parse the data and return a parsed data object or None if an error occurs

Parameters:

data – data to be parsed

Returns:

parsed data object or None if an error occurs

save() Bib

Save a record in the ‘records’ folder

Versioning is supported. A suffix is added to the file path.

Example: records/NZ_991170519490005501/bib_991170519490005501_01.xml

Returns:

almapiwrapper.inventory.Bib

Note

If the record encountered an error, this method will be skipped.

sort_fields() Bib

Sort all the fields and subfields of the record

Returns:

Bib

Note

If the record encountered an error, this method will be skipped.

update() Bib

Update data

On IzBib records this method is used to change local fields. On NzBib records, other fields can be changed.

Returns:

almapiwrapper.inventory.Bib

Note

If the record encountered an error, this method will be skipped.