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
- 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.7.tar.gz
(5.5 kB
view details)
Built Distribution
File details
Details for the file apimapper-0.7.7.tar.gz
.
File metadata
- Download URL: apimapper-0.7.7.tar.gz
- Upload date:
- Size: 5.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.13.0 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 | d18b8ad2e8d43a042800864a3adc24782cdce6d90b65cef26fbed7b1041e963d |
|
MD5 | 3d7a11850aa8d03689dfafb1afdcedf4 |
|
BLAKE2b-256 | 22cf00be6ec8d2296dfdb83eeb599a71e762984ec9e6fc02a8421f63febf14d2 |
File details
Details for the file apimapper-0.7.7-py3-none-any.whl
.
File metadata
- Download URL: apimapper-0.7.7-py3-none-any.whl
- Upload date:
- Size: 7.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.13.0 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 | a8a3f124adff3e73e3fd7d9246f81ac0aff577a0a6dd850c7562c6ea079e7b77 |
|
MD5 | b45c9ed040ccfb834130e33db53b54bd |
|
BLAKE2b-256 | bcae0e5a17d065df533f58b1bdd023d70c7fd3da9066ab4102636f56a37b3dfe |