Skip to main content

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


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.5.tar.gz (5.3 kB view details)

Uploaded Source

Built Distribution

apimapper-0.7.5-py3-none-any.whl (7.8 kB view details)

Uploaded Python 3

File details

Details for the file apimapper-0.7.5.tar.gz.

File metadata

  • Download URL: apimapper-0.7.5.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

Hashes for apimapper-0.7.5.tar.gz
Algorithm Hash digest
SHA256 ddfeabca2f9d9abaacb6a26ea270aba30a14ad6aa9408a9f6b6682fe1bb7ee0e
MD5 a9a74f5f05b4adaa7972773f0a191166
BLAKE2b-256 e7454e21671cb6bb5642502d19c409d29b05dfc6ce2e134c554849e6c1013328

See more details on using hashes here.

File details

Details for the file apimapper-0.7.5-py3-none-any.whl.

File metadata

  • Download URL: apimapper-0.7.5-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

Hashes for apimapper-0.7.5-py3-none-any.whl
Algorithm Hash digest
SHA256 9ffcc4d07776648be1720d666c9484f9451b0a6f136fceb971a53e663872ad11
MD5 2a746ca844c4379c7f2b8d2e1eceda54
BLAKE2b-256 f8f1bb232a426ede7f40449aeecf8bf5bdebdb64321ba3c71fee2c3372e6659e

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page