Skip to main content

Grab data from Atom API with Python

Project description

Python AtoM API

This is a simple library for interacting with an AtoM archive within Python. This library works with Python version 3, and has been tested with AtoM version 2.5. All of the API interactions specified in the AtoM documentation all have easy-to-call python functions associated with them in this library. This includes:

  • Browsing Taxonomies
  • Browsing Information Objects
  • Reading Information Objects

This library also implements a virtual endpoint that can be used to retrieve all of the authorities stored in the archive. It does this by treating the front-end application as an API endpoint. For this reason, this operation is more fragile than calling the API directly and is not guaranteed to work with every version of AtoM and every theme.

Install

python -m pip install atomapi

Usage

To use the API, you will require an AtoM API key. To use the virtual API, you do not need an API key, but please use it responsibly since the virtual API can easily make over 100 requests depending on how many items you have in AtoM. This may or may not put undue stress on the server.

There are three concrete API endpoint classes that use the actual API:

  • endpoints.BrowseTaxonomyEndpoint
  • endpoints.BrowseInformationObjectEndpoint
  • endpoints.ReadInformationObjectEndpoint

There are also three concrete Virtual API endpoint classes that make use of the front end application and treat is as an API:

  • virtualendpoints.VirtualBrowseTaxonomyEndpoint
  • virtualendpoints.VirtualBrowseAuthorityEndpoint
  • virtualendpoints.VirtualBrowseAuthorityRefCodeEndpoint

Note that the virtual endpoints have been tested on AtoM version 2.5, with the default arDominionPlugin theme. The virtual endpoints are not guaranteed to work with other versions of AtoM or highly customized themes. That being said, it would be easy to create a new endpoint that takes into account the modifed markup or CSS in a custom theme.

To view examples on how to use each endpoint, go to the examples code documentation.

Simple Example

To get data from the API, you will need to create a session object from the session factory. There are two types of sessions, default, and f5, for most AtoM instances, a default session will be sufficient.

from atomapi.sessions import session_factory

my_session = session_factory.create(name='default', url='https://youratom.com')

Once you've created a session, you can use it with any of the real and virtual endpoints. You may also reuse this session variable with as many endpoints as you like.

from atomapi.sessions import session_factory
from atomapi.endpoints import BrowseTaxonomyEndpoint
from atomapi.virtualendpoints import VirtualBrowseTaxonomyEndpoint

my_session = session_factory.create('default', 'https://youratom.com')

real_taxonomy_endpoint = BrowseTaxonomyEndpoint(my_session, api_key='1234567890')
virtual_taxonomy_endpoint = VirtualBrowseTaxonomyEndpoint(my_session)

Once your endpoints are set up, you can call the get function on them to get data.

from atomapi.taxonomies import DefaultTaxonomyIds

subjects = real_taxonomy_endpoint.get(DefaultTaxonomyIds.SUBJECTS.value)
places = virtual_taxonomy_endpoint.get(DefaultTaxonomyIds.PLACES.value)

The virtual API will take a lot longer to fetch the same amount of data as the real API since it is scraping the web page.

For more examples, go to the examples code documentation.

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

atomapi-0.0.2.tar.gz (11.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

atomapi-0.0.2-py3-none-any.whl (14.5 kB view details)

Uploaded Python 3

File details

Details for the file atomapi-0.0.2.tar.gz.

File metadata

  • Download URL: atomapi-0.0.2.tar.gz
  • Upload date:
  • Size: 11.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/50.3.0 requests-toolbelt/0.9.1 tqdm/4.46.1 CPython/3.7.7

File hashes

Hashes for atomapi-0.0.2.tar.gz
Algorithm Hash digest
SHA256 540d30a1c75a74d4199214ad7ec467838525f2a478880445a2e1497e8b312103
MD5 230d029180ea5a94d3d377d5f07bc879
BLAKE2b-256 ddd4265d2dadccc3747080fd1ab3980b49c45253f811c02f07d078e1e1e31090

See more details on using hashes here.

File details

Details for the file atomapi-0.0.2-py3-none-any.whl.

File metadata

  • Download URL: atomapi-0.0.2-py3-none-any.whl
  • Upload date:
  • Size: 14.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/50.3.0 requests-toolbelt/0.9.1 tqdm/4.46.1 CPython/3.7.7

File hashes

Hashes for atomapi-0.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 e2fc6c9408c8f64ad124420713ea67477756725002564d0dd6dd98c7557cc840
MD5 f6202c7de389fa674a1add340b8aac1e
BLAKE2b-256 d937cf1cf9bbe4904565f505881c2ce18078e81b543eb505cf579d665584d667

See more details on using hashes here.

Supported by

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