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.3.tar.gz
(5.3 kB
view details)
Built Distribution
File details
Details for the file apimapper-0.7.3.tar.gz
.
File metadata
- Download URL: apimapper-0.7.3.tar.gz
- Upload date:
- Size: 5.3 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 | 830e5cf400de2eaa2cd9a4367085cfac1f1af55d54458c339ac68d80618a9ddb |
|
MD5 | d8fd09bdc5b9d3839226e7c3ffcba349 |
|
BLAKE2b-256 | e779157fbf7efe69a2d32f210be7a32c72ce585c47ab18077f40fffe8a4f0eb8 |
File details
Details for the file apimapper-0.7.3-py3-none-any.whl
.
File metadata
- Download URL: apimapper-0.7.3-py3-none-any.whl
- Upload date:
- Size: 7.8 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 | c418019c9213234eec498cbe8ed9c38ceb66375bb049698f4802f1fb482dc703 |
|
MD5 | 489aff8be41004afe9346c2b69dd9c16 |
|
BLAKE2b-256 | 2f6802b54d34c323b5150abb9b2b50f9bd4f649a31adb9f21f13ee60200f8128 |