Skip to main content
Pre-release

This release is a pre-release and may not be stable for production use.

A thoroughly typed Python client for the Openverse API.

Repository PyPI - Version PyPI - Python Version

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.

Shared HTTPx client session

If you already use HTTPx and utilised a shared client session, you may pass this to the Openverse client constructors.

from openverse_api_client import OpenverseClient
import httpx

httpx_client = httpx.Client()

openverse = OpenverseClient(
    httpx_client=httpx_client,
)

The same API applies for the asynchronous Openverse client, but requires httpx.AsyncClient instead.

When using a shared HTTPx client session do not call close on the Openverse client as this will close the shared HTTPx instance. Likewise, do not use the Openverse client context manager if passing in a shared client, the context manager will close your shared HTTPx client on context exit.

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.

Release files for openverse-api-client 0.0.1a3

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

Source distribution (sdist)

Source distribution for openverse-api-client 0.0.1a3
File Size Uploaded
openverse_api_client-0.0.1a3.tar.gz 15.5 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for openverse-api-client 0.0.1a3
File Interpreter ABI Platform
openverse_api_client-0.0.1a3-py3-none-any.whl Python 3 none any Details

Total release size:40.2 kB

Release files / openverse_api_client-0.0.1a3.tar.gz

Download URL openverse_api_client-0.0.1a3.tar.gz
Size 15.5 kB
Tags Source
SHA-256 checksum
How to use checksums
0312caea94bdc6b988e02260295647817541f1f12620e5a15b7cab1083135fc6
BLAKE2b-256 checksum
How to use checksums
e001bca05836f500f73bb1003b84d39567fcd49917129dca990f6d2dac9568f6
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.0.0 CPython/3.11.8

Release files / openverse_api_client-0.0.1a3-py3-none-any.whl

Download URL openverse_api_client-0.0.1a3-py3-none-any.whl
Size 24.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
35ef571dcb0acfd3787f1762a846091b3abdd50b4489ca0388360d2dc5a160f8
BLAKE2b-256 checksum
How to use checksums
858047396d7d65b1661dd986e204bb3bc099a6484122e4aa4729489c0eb074cd
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.0.0 CPython/3.11.8

Release history Release notifications | RSS feed

0.0.1

2 release files

This release

0.0.1a3 This release

2 release files

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