Skip to main content

No project description provided

Project description

Humanloop Python Library

fern shield pypi

The Humanloop Python library provides convenient access to the Humanloop API from Python.

Installation

pip install humanloop

Usage

Instantiate and use the client with the following:

from humanloop.client import Humanloop

client = Humanloop(
    api_key="YOUR_API_KEY",
)
client.prompts.upsert(
    model="model",
)

Async Client

The SDK also exports an async client so that you can make non-blocking calls to our API.

from humanloop.client import AsyncHumanloop

client = AsyncHumanloop(
    api_key="YOUR_API_KEY",
)
await client.prompts.upsert(
    model="model",
)

Exception Handling

All errors thrown by the SDK will be subclasses of ApiError.

import humanloop

try:
    client.prompts.call(...)
except humanloop.core.ApiError as e: # Handle all errors
  print(e.status_code)
  print(e.body)

Advanced

Timeouts

By default, requests time out after 60 seconds. You can configure this with a timeout option at the client or request level.

from humanloop.client import Humanloop

client = Humanloop(
    ...,
    # All timeouts are 20 seconds
    timeout=20.0,
)

# Override timeout for a specific method
client.prompts.call(..., {
    timeout_in_seconds=20.0
})

Retries

The SDK is instrumented with automatic retries with exponential backoff. A request will be retried as long as the request is deemed retriable and the number of retry attempts has not grown larger than the configured retry limit (default: 2).

A request is deemed retriable when any of the following HTTP status codes is returned:

  • 408 (Timeout)
  • 429 (Too Many Requests)
  • 5XX (Internal Server Errors)

Use the max_retries request option to configure this behavior.

client.prompts.call(..., {
     max_retries=1
})

Custom HTTP client

You can override the httpx client to customize it for your use-case. Some common use-cases include support for proxies and transports.

import httpx

from humanloop.client import Humanloop

client = Humanloop(...,
    http_client=httpx.Client(
        proxies="http://my.test.proxy.example.com",
        transport=httpx.HTTPTransport(local_address="0.0.0.0"),
    ),
)

Pagination

Paginated requests will return a SyncPager or AsyncPager, which can be used as generators for the underlying object.

from humanloop.client import Humanloop

client = Humanloop(
    api_key="YOUR_API_KEY",
)
response = client.prompts.list_prompts()
for item in response:
    yield item
# alternatively, you can paginate page-by-page
for page in response.iter_pages():
    yield page

Contributing

While we value open-source contributions to this SDK, this library is generated programmatically. Additions made directly to this library would have to be moved over to our generation code, otherwise they would be overwritten upon the next generated release. Feel free to open a PR as a proof of concept, but know that we will not be able to merge it as-is. We suggest opening an issue first to discuss with us!

On the other hand, contributions to the README are always very welcome!

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

humanloop-0.8.0b0.tar.gz (71.4 kB view details)

Uploaded Source

Built Distribution

humanloop-0.8.0b0-py3-none-any.whl (167.2 kB view details)

Uploaded Python 3

File details

Details for the file humanloop-0.8.0b0.tar.gz.

File metadata

  • Download URL: humanloop-0.8.0b0.tar.gz
  • Upload date:
  • Size: 71.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.5.1 CPython/3.8.18 Linux/5.15.0-1064-azure

File hashes

Hashes for humanloop-0.8.0b0.tar.gz
Algorithm Hash digest
SHA256 1b7c6f60cc347c7091a243213b0077d8040f7398cd403979cdfc03edf18ab71f
MD5 43f04f25e6481d36a1d82d0b899a10cc
BLAKE2b-256 b6e57a62d1a8036c31bb6e34152e5fb0027f266852650755e158baa45af916e0

See more details on using hashes here.

File details

Details for the file humanloop-0.8.0b0-py3-none-any.whl.

File metadata

  • Download URL: humanloop-0.8.0b0-py3-none-any.whl
  • Upload date:
  • Size: 167.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.5.1 CPython/3.8.18 Linux/5.15.0-1064-azure

File hashes

Hashes for humanloop-0.8.0b0-py3-none-any.whl
Algorithm Hash digest
SHA256 ba2ba86fc76e7c71bfb1e6e8d03250ed3c3ad4b90dc8cd86c6a06ee91981ef31
MD5 97d18c0729c0b5150b0d3cbe028adab5
BLAKE2b-256 11e81bb9771d519d6345a65509a746add4fe3637ece5a9165b27174db98e11e9

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