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 beTrue
orFalse
. 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 toobject
but others likeagent
,taxon
, andplace
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 asNone
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 to1
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 to0.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 oftype
values, egObject,Specimen
orPerson
)
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file askCO-0.1.6.tar.gz
.
File metadata
- Download URL: askCO-0.1.6.tar.gz
- Upload date:
- Size: 6.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/5.0.0 CPython/3.12.2
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | b21dcd1e9ac484b5e0a548d23e0441a48d2d1f796c81cd94eb96ac76440c0e67 |
|
MD5 | 8c6654e8aea0d62454367378608f0c7c |
|
BLAKE2b-256 | 565100446932176d18534c727254ead36e63afdf38534215ddc0012da3ab8015 |
File details
Details for the file askCO-0.1.6-py3-none-any.whl
.
File metadata
- Download URL: askCO-0.1.6-py3-none-any.whl
- Upload date:
- Size: 6.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/5.0.0 CPython/3.12.2
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 493eef0e1dd5a83b9cea5f40467220a2016aecbd0935b7d31b7a8020a174e209 |
|
MD5 | 9cd6e508eb8e94fee16628c4b7a36923 |
|
BLAKE2b-256 | a4ab3bb3f405052cad9e735bfc49f2499afbb820f65dc26dc4709852dc627081 |