Skip to main content

API Wrapper

Install package

  • from PyPi: pip install apimapper
  • from source: pip install -e .

Unit Testing

pytest

Usage

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

Metadata

Release files for apimapper 0.7.9

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for apimapper 0.7.9
File Size Uploaded Provenance
apimapper-0.7.9.tar.gz 7.3 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for apimapper 0.7.9
File Interpreter ABI Platform
apimapper-0.7.9-py2.py3-none-any.whl Python 3, Python 2 none any Details

Total release size: 15.5 kB

Release files / apimapper-0.7.9.tar.gz

Download URL apimapper-0.7.9.tar.gz
Size 7.3 kB
Tags Source
SHA-256 checksum
How to use checksums
7aedb0c9c8b9f61978b15334fbb284db7fa15e5a4b8bf36dfe2988a5c9b82e40
BLAKE2b-256 checksum
How to use checksums
68c6eab4525895270166631c93dcf55687b5bd0b37e5f83be5b2445fd2488628
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.8.10

Release files / apimapper-0.7.9-py2.py3-none-any.whl

Download URL apimapper-0.7.9-py2.py3-none-any.whl
Size 8.2 kB
Tags Python 2 Python 3
SHA-256 checksum
How to use checksums
6bb4d07c92697763cac4d1dfd279b4e11d94fc2f35e40f417ea42be638028ac5
BLAKE2b-256 checksum
How to use checksums
6c8753017e236081c5b986e35ef08a5c54542f6251a66c6e33074a94baca0d30
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.8.10

Security for apimapper 0.7.9

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page