Python client for the Openverse API
Project description
A thoroughly typed Python client for the Openverse API.
Installation
pip install openverse-api-client
Usage
The Openverse API client has a single external dependency on httpx. HTTPx was chosen because the precense of both a synchronous and asynchronous HTTP client from a single library, with nearly identical APIs, made it easy to generate the Python client using the generator.
from openverse_api_client import OpenverseClient, AsyncOpenverseClient
with OpenverseClient() as openverse:
images = openverse.GET_v1_images(
q="dogs",
license="by-nc-sa",
source=["flickr", "wikimedia"],
)
with AsyncOpenverseClient() as async_openverse:
audio = await async_openverse.GET_v1_audio(
q="birds",
license="by",
source=["freesound"],
)
Using the Openverse client as context managers will automatically close the underlying HTTPx client. Call close on the Openverse client to manually close the underlying HTTPx client when not using the context manager.
Authentication
By default, the clients will make unauthenticated requests. Pass client_id and client_secret to the client constructor to authenticate requests. The client automatically handles requesting tokens and token expiration.
from openverse_api_client import OpenverseClient
# The same API applies to the async client
authenticated_openverse = OpenverseClient(
client_id="...",
client_secret="...",
)
Alternative Openverse API instances
The clients reference the official production Openverse API instance by default, https://api.openverse.engineering. If you would like to send requests to a different API instance, pass base_url to the constructor:
from openverse_api_client import OpenverseClient
# The same API applies to the async client
localhost_openverse = OpenverseClient(
base_url="localhost:50280",
)
Development
Please refer to the repository README
License
openverse-api-client is distributed under the terms of the GNU Lesser General Public License v3.0 or later license.
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 openverse_api_client-0.0.1a3.tar.gz
.
File metadata
- Download URL: openverse_api_client-0.0.1a3.tar.gz
- Upload date:
- Size: 15.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.0.0 CPython/3.11.8
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0312caea94bdc6b988e02260295647817541f1f12620e5a15b7cab1083135fc6 |
|
MD5 | 8fa71a883ba35ed9f44a463bb47d06eb |
|
BLAKE2b-256 | e001bca05836f500f73bb1003b84d39567fcd49917129dca990f6d2dac9568f6 |
File details
Details for the file openverse_api_client-0.0.1a3-py3-none-any.whl
.
File metadata
- Download URL: openverse_api_client-0.0.1a3-py3-none-any.whl
- Upload date:
- Size: 24.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.0.0 CPython/3.11.8
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 35ef571dcb0acfd3787f1762a846091b3abdd50b4489ca0388360d2dc5a160f8 |
|
MD5 | eab2423fdddde791e4169a873b9ab349 |
|
BLAKE2b-256 | 858047396d7d65b1661dd986e204bb3bc099a6484122e4aa4729489c0eb074cd |