Skip to main content

No project description provided

Project description

pylangdb

pylangdb is a Python package for interacting with LangDb APIs. Please find out more at https://langdb.ai/.

Installation

To install pylangdb, use pip:

pip install pylangdb

Usage

Initialize LangDb Client

from pylangdb import LangDb

# Initialize with API key and project ID
client = LangDb(api_key="your_api_key", project_id="your_project_id")

Chat Completions

messages = [
    {"role": "system", "content": "You are a helpful assistant."},
    {"role": "user", "content": "Say hello!"}
]

response = client.completion(
    model="gemini-1.5-pro-latest",
    messages=messages,
    temperature=0.7,
    max_tokens=100
)

Thread Operations

Get Messages

Retrieve messages from a specific thread:

messages = client.get_messages(thread_id="your_thread_id")

# Access message details
for message in messages:
    print(f"Type: {message.type}")
    print(f"Content: {message.content}")
    if message.tool_calls:
        for tool_call in message.tool_calls:
            print(f"Tool: {tool_call.function.name}")

Get Thread Cost

Get cost and token usage information for a thread:

cost = client.get_cost(thread_id="your_thread_id")
print(f"Total cost: ${cost.total_cost:.4f}")
print(f"Input tokens: {cost.total_input_tokens}")
print(f"Output tokens: {cost.total_output_tokens}")

Analytics

Get analytics data for specific tags:

# Get raw analytics data
analytics = client.get_analytics(
    tags="model1,model2",
    start_time_us=None,  # Optional: defaults to 24 hours ago
    end_time_us=None     # Optional: defaults to current time
)

# Get analytics as a pandas DataFrame
df = client.get_analytics_dataframe(
    tags="model1,model2",
    start_time_us=None,
    end_time_us=None
)

Development

Setting up the environment

  1. Clone the repository
  2. Create a .env file with your credentials:
LANGDB_API_KEY="your_api_key"
LANGDB_PROJECT_ID="your_project_id"
LANGDB_TEST_THREAD_ID="your_test_thread_id"  # Optional: for running tests

Running Tests

python -m unittest tests/client.py -v

Publishing

poetry build
poetry publish

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

pylangdb-0.2.0.tar.gz (5.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pylangdb-0.2.0-py3-none-any.whl (6.3 kB view details)

Uploaded Python 3

File details

Details for the file pylangdb-0.2.0.tar.gz.

File metadata

  • Download URL: pylangdb-0.2.0.tar.gz
  • Upload date:
  • Size: 5.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.0.1 CPython/3.10.12 Linux/5.15.0-131-generic

File hashes

Hashes for pylangdb-0.2.0.tar.gz
Algorithm Hash digest
SHA256 6624c001276860141e98e9554c3b37c52bce21db52b63f17acd423f6e67006f5
MD5 34391160637250235d86eaa668082db5
BLAKE2b-256 a5e4ab2f6071f046dcc508c902841b8873bd6964f7fcc26b16f1a3079e2a208d

See more details on using hashes here.

File details

Details for the file pylangdb-0.2.0-py3-none-any.whl.

File metadata

  • Download URL: pylangdb-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 6.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.0.1 CPython/3.10.12 Linux/5.15.0-131-generic

File hashes

Hashes for pylangdb-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 f3b32512d9bf46641f13664580e5e444961a8cbc48b6b04373caf0ba0c7204a1
MD5 5d3a3c158e2f7a19a2f448f557d35a34
BLAKE2b-256 894a46ae622131c4f242ed0701eea00f36190c2fef05c8fc5e70b1d7e9f03c59

See more details on using hashes here.

Supported by

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