API Mapper
Project description
API Wrapper
Install package
- from PyPi: pip install apimapper
- from source: pip install -e .
Unit Testing
tests> python -m pytest
Usage
- See https://github.com/acdh-oeaw/apimapper/blob/develop/demo/APIMapper%20Demo.ipynb
- Multiple APIs (GND and VIAF) mapped to a common JSON schema
VIAF only returns VIAF ID - which is contructed into a url using a "rule"
from apimapper import APIMapper
from apimapper import config
GND_PERSON_MAP = {config.DIRECT: {'uri': 'id',
'label': 'label'}}
VIAF_PERSON_MAP = {config.RESULT: 'result',
config.FILTER: {'nametype': 'personal'},
config.DIRECT: {'label': 'displayForm'},
config.RULES: {'uri': {config.RULE: '"http://www.viaf.org/viaf/{p1}"',
config.FIELDS: {'p1': 'viafid'}}}}
GND_PERSON_SOURCE = {config.URL: 'https://lobid.org/gnd/search',
config.QUERY_FIELD: 'q',
config.PAYLOAD: {'format':'json:suggest',
'filter': 'type:Person'}}
VIAF_PERSON_SOURCE = {config.URL: 'http://www.viaf.org/viaf/AutoSuggest',
config.QUERY_FIELD: 'query'}
gnd = APIMapper(GND_PERSON_SOURCE, GND_PERSON_MAP)
viaf = APIMapper(VIAF_PERSON_SOURCE, VIAF_PERSON_MAP)
apis = [gnd, viaf]
results = []
for api in apis:
res = api.fetch_results('Pratchett')
results.extend(res)
print(results)
- Using mapping rules
Splitting the GND label field into meaningful subparts
from apimapper import APIMapper
from apimapper import config
GND_PERSON_SOURCE = {config.URL: 'https://lobid.org/gnd/search',
config.QUERY_FIELD: 'q',
config.PAYLOAD: {'format':'json:suggest',
'filter': 'type:Person'}}
GND_PERSON_MAP = {config.DIRECT: {'label': 'label',
'uri': 'id'},
config.RULES: {'source': {config.RULE: '"GND"'},
'label_name': {config.RULE: '"{p1}".split("|")[0].strip()',
config.FIELDS: {'p1': 'label'}},
'label_year': {config.RULE: '"{p1}".split("|")[1].strip() if "{p1}".split("|")[1].strip()[0].isnumeric() else ""',
config.FIELDS: {'p1': 'label'}},
'label_profession': {config.RULE: '"{p1}".split("|")[2].strip() if "{p1}".split("|")[1].strip()[0].isnumeric() else "{p1}".split("|")[1].strip()',
config.FIELDS: {'p1': 'label'}}}}
api = APIMapper(GND_PERSON_SOURCE, GND_PERSON_MAP)
res = api.fetch_results('Rosalind Franklin')
- More example usage in apimapper/demo
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
apimapper-0.7.8.tar.gz
(5.5 kB
view details)
Built Distribution
File details
Details for the file apimapper-0.7.8.tar.gz
.
File metadata
- Download URL: apimapper-0.7.8.tar.gz
- Upload date:
- Size: 5.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.32.1 CPython/3.6.8
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 403ebea6e2881499f2daf36743e584338582572cc5a1a238e2778ac66d548e44 |
|
MD5 | 215f9d0709b4afa3e13dc66ceb24e621 |
|
BLAKE2b-256 | 644d33420db06049e628e212e597e281b55ac5c5a023bcee42c409cad6c04f59 |
File details
Details for the file apimapper-0.7.8-py3-none-any.whl
.
File metadata
- Download URL: apimapper-0.7.8-py3-none-any.whl
- Upload date:
- Size: 7.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.32.1 CPython/3.6.8
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7027c155214cdb87db0c19da29441f7255f129b4d44e28ecf57333a4383539ef |
|
MD5 | fdf51704512dee53efa64613b5a9ed24 |
|
BLAKE2b-256 | dac398cbe411002a3dfef1cdcc974c2e05fcbf27fee9572d18d3c4cedc612616 |