Pybman
Synopsis
This is a Python package for interacting with MPG.PuRe via the PubMan REST API.
Installation
You can simply install this package via PyPI:
pip install pybman
… or by cloning the repository:
git clone https://github.com/herreio/pybman.git
cd pybman
Documentation
A minimal documentation can be found on Read the Docs.
Usage
Launch the Python interpreter and start by importing the necessary modules:
from pybman import Client
from pybman import extract
# initialize client
cl = Client()
# retrieve data of specific context
ctx = cl.get_data(ctx_id="ctx_924547")
# number of records in this context
num_records = ctx.num
# access records via index
item = ctx.records[0]
# get genre from item ...
genre = extract.genre_from_item(item)
print("GENRE:", genre)
# ... or get genres and associated items from context
genres = ctx.get_genres()
# list all genres used in this context
list(genres.keys())
# get all articles (list of item IDs) from context
articles = genres['ARTICLE']
# get data of item (article) by id
item = ctx.get_item(articles[0])
# get title from item
title = extract.title_from_item(item)
print("TITLE:", title)
# get publication date from item
date = extract.date_from_item(item)
print("PUBLISHED:", date)
# get creators (persons) from item
persons = extract.persons_from_item(item)
for person in persons:
role = extract.role_from_creator(person)
first_name, last_name = extract.persons_name_from_creator(person)
id_val, id_type = extract.persons_id_from_creator(person)
print(role+':', first_name, last_name, '('+ id_val +')')
Beside data retrieval and browsing Pybman also allows to update items! Because this process requires certain rights, you have to provide credentials. The easiest way is to create a secret.json file with your PuRe login (userName:userPassword) and hand in the path pointing to it when creating the client instance. (Please use a different location for storing the secret.json-file than the one in this repo as it will be tracked by git or alternatively tell git before editing the file to not take care of your changes by running the command git update-index --assume-unchanged conf/secret.json.)
# intialize client instance (login)
cl_auth = Client(secret="./conf/secret.json")
# retrieve context you are allowed to modify
ctx = cl_auth.get_data(ctx_id="ctx_924547")
# choose item to change
item = ctx.records[0]
# change title (string strip)
title = extract.title_from_item(item)
title = title.strip()
item['data']['metadata']['title'] = title
# get identifier from item
identifier = extract.idx_from_item(item)
# comment on the changes
comment = 'delete unnecessary white space'
# update data in repository
cl_auth.update_data(identifier, item['data'], comment)
# to change values in collection of items use inspector class
from pybman import Inspector
from pybman import DataSet
# create data set of released items
ctx_released = DataSet(data_id="ctx_924547_released", raw=ctx.get_items_released())
# create inspector instance of all released items from context
inspector = Inspector(cl_auth, ctx_released.records)
# strip title strings, i.e. remove leading and trailing white spaces
titles = inspector.clean_titles()
print("successfully cleaned", titles, "titles!")
Metadata
Release files for pybman 2019.10.17
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| pybman-2019.10.17.tar.gz | 31.1 kB | Without provenance | Details for pybman-2019.10.17.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| pybman-2019.10.17-py3-none-any.whl | Python 3 | none | any | Details for pybman-2019.10.17-py3-none-any.whl |
Total release size: 66.2 kB
Release files / pybman-2019.10.17.tar.gz
| Download URL | pybman-2019.10.17.tar.gz |
|---|---|
| Size | 31.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
24b44340a50fc24aa44855c134461398d3426f218b873c08d3ac7690ea59091c
|
|
BLAKE2b-256 checksum How to use checksums |
865976da60b168518304f62ac0bef15ab3f3279d0c671ad3fc5a4dcea0e60934
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/1.12.1 pkginfo/1.5.0.1 requests/2.18.4 setuptools/40.6.3 requests-toolbelt/0.8.0 tqdm/4.19.9 CPython/3.6.5
|
Release files / pybman-2019.10.17-py3-none-any.whl
| Download URL | pybman-2019.10.17-py3-none-any.whl |
|---|---|
| Size | 35.1 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
14c7f1668c10d06068d352c2a697d5dcc4ead66843853f312014bbdfae865f21
|
|
BLAKE2b-256 checksum How to use checksums |
d15c8bd631fcf0fee5da5ad9486c48fbb77a0a847a0133a45d90c7e3686b5cff
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/1.12.1 pkginfo/1.5.0.1 requests/2.18.4 setuptools/40.6.3 requests-toolbelt/0.8.0 tqdm/4.19.9 CPython/3.6.5
|
Security for pybman 2019.10.17
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.