API Mapper
Project description
API Wrapper
Install package
- from PyPi: pip install apimapper
- from source: pip install -e .
Unit Testing
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.9.tar.gz
(7.3 kB
view details)
Built Distribution
File details
Details for the file apimapper-0.7.9.tar.gz
.
File metadata
- Download URL: apimapper-0.7.9.tar.gz
- Upload date:
- Size: 7.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.8.10
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7aedb0c9c8b9f61978b15334fbb284db7fa15e5a4b8bf36dfe2988a5c9b82e40 |
|
MD5 | f4d84b613b8f8ae64626a67ee59e1255 |
|
BLAKE2b-256 | 68c6eab4525895270166631c93dcf55687b5bd0b37e5f83be5b2445fd2488628 |
File details
Details for the file apimapper-0.7.9-py2.py3-none-any.whl
.
File metadata
- Download URL: apimapper-0.7.9-py2.py3-none-any.whl
- Upload date:
- Size: 8.2 kB
- Tags: Python 2, Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.8.10
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6bb4d07c92697763cac4d1dfd279b4e11d94fc2f35e40f417ea42be638028ac5 |
|
MD5 | d725500ea1aebf190111718224759c52 |
|
BLAKE2b-256 | 6c8753017e236081c5b986e35ef08a5c54542f6251a66c6e33074a94baca0d30 |