Skip to main content

adlib-client

A Python wrapper for monetizing LLM output with AdLib.

Install

Install from PyPI:

pip install adlib-client

Required API keys

AdLib requires two keys:

ADLIB_API_KEY=your_adlib_api_key_here
ADLIB_CHATBOT_PUBLIC_KEY=your_chatbot_public_key_here

You can provide them using environment variables (in a .env file) or directly when creating AdLib():

from adlib_client import AdLib

adlib = AdLib(
    adlib_api_key="your_adlib_api_key_here",
    adlib_chatbot_api_key="your_chatbot_public_key_here",
)

Authorization on Initialization

When you create an instance of AdLib(), it automatically attempts to validate your credentials against the AdLib service.

  • Success: The object is initialized and ready for use.
  • Missing Keys: If either key is missing (and not found in environment variables), an Exception is raised immediately.
  • Invalid Keys: If the keys are provided but rejected by the server, a ValueError is raised with the specific error message from the service.

Basic usage

from adlib_client import AdLib

# Automatically loads keys from environment or .env
adlib = AdLib()

llm_output = "Here is the answer from your model."
adified_output = adlib.adify(llm_output)

print(adified_output)

adlib.adify() sends text to AdLib and returns the final transformed output string. If an ad is inserted, it's included in the string; otherwise, the original text is returned.

Use AdLib as a decorator

You can wrap your generation functions directly:

from adlib_client import AdLib

adlib = AdLib()

@adlib.adify
def generate_answer(prompt: str) -> str:
    # Your LLM logic here
    answer = ...
    return answer

# The returned value is now automatically adified
print(generate_answer("What is the weather?"))

Error Handling

  • Initialization: Exception for missing keys, ValueError for invalid keys.
  • Network Errors: Failed HTTP requests raise standard requests exceptions (e.g., connection issues).
  • Service Errors: If the adify service fails during a call, adify() safely returns the original LLM output.

Notes

  • adlib.adify() returns the transformed text string directly.
  • Use adify when you want to wrap LLM outputs or decorate generation functions.

Release files for adlib-client 0.1.9

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

Source distribution (sdist)

Source distribution for adlib-client 0.1.9
File Size Uploaded
adlib_client-0.1.9.tar.gz 3.2 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for adlib-client 0.1.9
File Interpreter ABI Platform
adlib_client-0.1.9-py3-none-any.whl Python 3 none any Details

Total release size: 6.8 kB

Release files / adlib_client-0.1.9.tar.gz

Download URL adlib_client-0.1.9.tar.gz
Size 3.2 kB
Tags Source
SHA-256 checksum
How to use checksums
10be0a44bb1f5619eec0183d366b008283522f110544ba668524266fde59ecbc
BLAKE2b-256 checksum
How to use checksums
8e9959f81650060aa4d097718e30a59c953f00954f1b2dd59bb0e664b9600cfc
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.13.7

Release files / adlib_client-0.1.9-py3-none-any.whl

Download URL adlib_client-0.1.9-py3-none-any.whl
Size 3.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
94e6128543727416a1be27e59ce29aa829cc4c45553770d86adc8f3e59263a18
BLAKE2b-256 checksum
How to use checksums
7911fc48cb5c41c31e2414292851b838112be9e55394a4f6195e6b9cd1d596b4
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.13.7

Release history Release notifications | RSS feed

This release

0.1.9 This release

2 release files

0.1.8

2 release files

0.1.6

2 release files

0.1.4

2 release files

0.1.2

2 release files

0.1.0

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