Skip to main content

Python interface for Te Papa's collections API

Project description

askCO: search and query records from Te Papa's collections API

This script provides an interface for getting data from the Museum of New Zealand Te Papa Tongarewa. With it, you can run searches and request individual records, which are returned as python objects.

See the API documentation for what's available and how to construct searches.

Te Papa's API requires a registration key in the headers of each request – go to https://data.tepapa.govt.nz/docs/register.html to register. I recommend adding the API key to an environment variable called 'TE-PAPA-KEY', and then calling that from your script to pass to askCO.

Installation

Install using pip: pip install askCO

askCO requires the requests module.

Run a search query

The tryCO.py file lays out a prepared search for a page of Myosotis specimen records in the Plants collection. It calls the API key, sets functional and query parameters, and sets up then runs the search request.

A Search request object uses:

  • quiet: Can be True or False. If False, askCO prints messages to the console like the URL being requested.
  • timeout: How long in seconds before the query times out.
  • attempts: How many times a single query will be retried after an error like a timeout or connection error.
  • endpoint: Which API endpoint to query. Defaults to object but others like agent, taxon, and place are available.
  • query: The term you're searching for. If not searching for something specific, use the * wildcard.
  • filters: Any filters you want to use in a list of key/value pairs. Can specify a collection to search here.
  • fields: Cut the response down to specified fields. Leave as None to get the full record, or use a list of comma-separated fieldnames.
  • size: How many results to return at once.
  • start: Where to begin the page of results. Useful when requesting subsequent pages of a search.

The Scroll request object is similar, though it finds and returns all records, not just a page. It uses most of the same parameters, but not start. Scrolling works well with a size of 1000. It can also use:

  • duration: How long to keep the scroll query alive for on the API side. Defaults to 1 minute.
  • max_records: How many records to retrieve, if you don't want everything.
  • sleep: How long to wait between requests for scroll pages. Set this to 0.1 to ensure you avoid getting rate limited.

Search and scroll results are stored as a list of dictionaries in the records attribute of the request object.

HTTP status is stored as an integer in the status_code attribute.

Get a record

When requesting a single record, the Resource request object still uses:

  • api_key
  • quiet
  • timeout
  • attempts
  • endpoint

It also takes an irn parameter, the specific number for that record within the endpoint. Make sure you've set the correct endpoint - /object/123456 isn't the same as /agent/123456.

The record's data is stored as a dictionary in the response_text attribute of the request object.

HTTP status is stored as an integer in the status_code attribute.

Get related records by adding the following parameters:

  • related (set to True)
  • size (the number of related records to return)
  • types (a comma separated list of type values, eg Object,Specimen or Person)

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

askco-0.1.7.tar.gz (6.5 kB view details)

Uploaded Source

Built Distribution

askco-0.1.7-py3-none-any.whl (6.7 kB view details)

Uploaded Python 3

File details

Details for the file askco-0.1.7.tar.gz.

File metadata

  • Download URL: askco-0.1.7.tar.gz
  • Upload date:
  • Size: 6.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for askco-0.1.7.tar.gz
Algorithm Hash digest
SHA256 21fd7d00b679aa6c5b200c68ba748f00584052b86d9e0adbd775826026ff3987
MD5 275dcf9da72940931a86549c8e100037
BLAKE2b-256 2ea7fabdb74732eeef5f784d273264c26c7351d5e799a92670cb62b2cbfd5397

See more details on using hashes here.

Provenance

The following attestation bundles were made for askco-0.1.7.tar.gz:

Publisher: python-publish.yml on lucyschrader/askCO

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file askco-0.1.7-py3-none-any.whl.

File metadata

  • Download URL: askco-0.1.7-py3-none-any.whl
  • Upload date:
  • Size: 6.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for askco-0.1.7-py3-none-any.whl
Algorithm Hash digest
SHA256 e2c558455a1048e45aa868ee1b75cd272c81c26abde99df69cf2f063cbf02e08
MD5 cae224fab584b5373cc3875a7a2e6fc5
BLAKE2b-256 9414344ff04c6bcbbb14b609a5fd1d865ad14a9b28b40e6742ba50e3d00cd21f

See more details on using hashes here.

Provenance

The following attestation bundles were made for askco-0.1.7-py3-none-any.whl:

Publisher: python-publish.yml on lucyschrader/askCO

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

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