Skip to main content

Python client for the Openverse API

Project description

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.

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

openverse_api_client-0.0.1a3.tar.gz (15.5 kB view details)

Uploaded Source

Built Distribution

openverse_api_client-0.0.1a3-py3-none-any.whl (24.7 kB view details)

Uploaded Python 3

File details

Details for the file openverse_api_client-0.0.1a3.tar.gz.

File metadata

File hashes

Hashes for openverse_api_client-0.0.1a3.tar.gz
Algorithm Hash digest
SHA256 0312caea94bdc6b988e02260295647817541f1f12620e5a15b7cab1083135fc6
MD5 8fa71a883ba35ed9f44a463bb47d06eb
BLAKE2b-256 e001bca05836f500f73bb1003b84d39567fcd49917129dca990f6d2dac9568f6

See more details on using hashes here.

File details

Details for the file openverse_api_client-0.0.1a3-py3-none-any.whl.

File metadata

File hashes

Hashes for openverse_api_client-0.0.1a3-py3-none-any.whl
Algorithm Hash digest
SHA256 35ef571dcb0acfd3787f1762a846091b3abdd50b4489ca0388360d2dc5a160f8
MD5 eab2423fdddde791e4169a873b9ab349
BLAKE2b-256 858047396d7d65b1661dd986e204bb3bc099a6484122e4aa4729489c0eb074cd

See more details on using hashes here.

Supported by

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