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

Uploaded Source

Built Distribution

apimapper-0.7.2-py3-none-any.whl (7.6 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: apimapper-0.7.2.tar.gz
  • Upload date:
  • Size: 5.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/3.6.8

File hashes

Hashes for apimapper-0.7.2.tar.gz
Algorithm Hash digest
SHA256 d0809aeb9dd2209ac9ebc461ce43961dd08050ae7cf810b09ee14f53505b7f89
MD5 d89047fd2193c53bc653d9169f5d5384
BLAKE2b-256 f3c4ec474bdb68624ad3f7b8ca5235f9f68b669e8203e02c0dc20d8de8266fd7

See more details on using hashes here.

File details

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

File metadata

  • Download URL: apimapper-0.7.2-py3-none-any.whl
  • Upload date:
  • Size: 7.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/3.6.8

File hashes

Hashes for apimapper-0.7.2-py3-none-any.whl
Algorithm Hash digest
SHA256 6b9811c2eb6381c353bb74cd3246672f487802459abd29ebe35951f036d45d14
MD5 83eb46c9b0100654d899986a60d37e62
BLAKE2b-256 a4b859d8bf0624b820f957264b293547423362e79a2acb7ab4c8b5fcfec9a419

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