Skip to main content

Client for MuseumPlus

Project description

museumpy

museumpy is a client for python to get data from Zetcom MuseumPlus instances.

Table of Contents

Installation

museumpy is available on PyPI, so to install it simply use:

$ pip install museumpy

Usage

See the examples directory for more scripts.

search

import museumpy

records = museumpy.search(
    base_url='https://mpzurichrietberg.zetcom.com/MpWeb-mpZurichRietberg',
    field='ObjObjectNumberTxt',
    value='2019.184',
)


for record in records:
    print(record)

The return value of search is iterable, so you can easily loop over it. Or you can use indices to access elements, e.g. records[1] to get the second element, or records[-1] to get the last one.

Even slicing is supported, so you can do things like only iterate over the first 5 elements using

for records in records[:5]:
   print(record)

fulltext_search

import museumpy

records = museumpy.fulltext_search(
    base_url='https://test.zetcom.com/MpWeb-mpTest',
    query='Patolu',
)


for record in records:
    print(record)

Advanced usage

For more advanced usage of this library, it is recommened to first create a client instance and then use this to request data:

import museumpy
import requests

s = requests.Session()
s.auth = ('user', 'pass')
s.headers.update({'Accept-Language': 'de'})

client = museumpy.MuseumPlusClient(
    base_url='https://test.zetcom.com/MpWeb-mpTest',
    session=s
)

module_item

import museumpy

id = '98977'
module = 'Multimedia'
item = client.module_item(id, module)

download_attachement

import museumpy

id = '98977'
module = 'Multimedia'
# download attachment to a directory called `files`
attachment_path = client.download_attachment(id, module, 'files')
print(attachment_path)

Custom mapping of fields

There are most likely custom fields on the MuseumPlus Instance you want to query. The returned XML is converted to a python dict using the xmltodict library. The raw dict is returned on the raw key of the result:

import museumpy

records = museumpy.search(
    base_url='https://test.zetcom.com/MpWeb-mpTest',
    query='Patolu',
)
for record in records:
    print(record['raw'])

For convenience a default mapping is provided to access some fields more easily:

for record in records:
    print(record['hasAttachments'])
    print(record['ObjObjectNumberTxt'])

If you want to customize this mapping, you can pass a map_function to the client, which is then used on all subsequent calls to search and fulltext_search:

import museumpy

def my_custom_map(record, xml_rec):
    NS = "http://www.zetcom.com/ria/ws/module"
    ID_XPATH = f".//{{{NS}}}dataField[@name='ObjObjectNumberTxt']/{{{NS}}}value"
    TITLE_XPATH = f".//{{{NS}}}repeatableGroup[@name='ObjObjectTitleGrp']//{{{NS}}}dataField[@name='TitleTxt']//{{{NS}}}value"

    xml_parser = museumpy.xmlparse.XMLParser()
    my_new_record = {
        'my_id': xml_parser.find(xml_rec, ID_XPATH).text,
        'my_title': xml_parser.find(xml_rec, TITLE_XPATH).text 
    }
    return my_new_record


client = museumpy.MuseumPlusClient(
    base_url='https://test.zetcom.com/MpWeb-mpTest',
    map_function=my_custom_map,
)

records = client.search(
    base_url='https://test.zetcom.com/MpWeb-mpTest',
    query='Patolu',
)
for record in records:
    print(record['my_id'])
    print(record['my_title'])

Release

To create a new release, follow these steps (please respect Semantic Versioning):

  1. Adapt the version number in museumpy/__init__.py
  2. Update the CHANGELOG with the version
  3. Create a pull request to merge develop into main (make sure the tests pass!)
  4. Create a new release/tag on GitHub (on the main branch)
  5. The publication on PyPI happens via GitHub Actions on every tagged commit

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

museumpy-0.4.1.tar.gz (10.4 kB view details)

Uploaded Source

Built Distribution

museumpy-0.4.1-py3-none-any.whl (9.2 kB view details)

Uploaded Python 3

File details

Details for the file museumpy-0.4.1.tar.gz.

File metadata

  • Download URL: museumpy-0.4.1.tar.gz
  • Upload date:
  • Size: 10.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.8.16

File hashes

Hashes for museumpy-0.4.1.tar.gz
Algorithm Hash digest
SHA256 fd83cc2c1cec1604ff894d204ba7d57eceed303890a66d9f5224f53f20b380b4
MD5 c7a3b3eacb0126dbc03c826ed367d6c3
BLAKE2b-256 b7a578f2b173f4feb4eaa0ea143f9c624e0fdce2262d8c73fb1547618b1dba9b

See more details on using hashes here.

File details

Details for the file museumpy-0.4.1-py3-none-any.whl.

File metadata

  • Download URL: museumpy-0.4.1-py3-none-any.whl
  • Upload date:
  • Size: 9.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.8.16

File hashes

Hashes for museumpy-0.4.1-py3-none-any.whl
Algorithm Hash digest
SHA256 fd3765ce46dc168916efcb1207105c1026592092fa995457cb8c1883c5ed116f
MD5 3dcbbc477f002d02daa212964a8feb67
BLAKE2b-256 6351158f9c77042de22b026647fc330f30916ea0dd488dda9832c4b83d0b18d8

See more details on using hashes here.

Supported by

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