pylangdb


Namepylangdb JSON
Version 0.2.5 PyPI version JSON
download
home_pageNone
SummaryNone
upload_time2025-02-10 04:23:41
maintainerNone
docs_urlNone
authorVivek
requires_python<4.0,>=3.10
licenseNone
keywords
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # 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:

```bash
pip install pylangdb
```

## Usage

### Initialize LangDb Client

```python
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

```python
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:

```python
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:

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

### Analytics

Get analytics data for specific tags:

```python
# 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:
```bash
LANGDB_API_KEY="your_api_key"
LANGDB_PROJECT_ID="your_project_id"
```

### Running Tests

```bash
python -m unittest tests/client.py -v
```

## Publishing

```bash
poetry build
poetry publish
            

Raw data

            {
    "_id": null,
    "home_page": null,
    "name": "pylangdb",
    "maintainer": null,
    "docs_url": null,
    "requires_python": "<4.0,>=3.10",
    "maintainer_email": null,
    "keywords": null,
    "author": "Vivek",
    "author_email": "vivek@langdb.ai",
    "download_url": "https://files.pythonhosted.org/packages/91/1f/68e233400633e2c2f5a5348be3fd6ecc95817869e085e8da5bcd620287ba/pylangdb-0.2.5.tar.gz",
    "platform": null,
    "description": "# pylangdb\n`pylangdb` is a Python package for interacting with `LangDb` APIs. Please find out more at https://langdb.ai/.\n\n## Installation\nTo install `pylangdb`, use pip:\n\n```bash\npip install pylangdb\n```\n\n## Usage\n\n### Initialize LangDb Client\n\n```python\nfrom pylangdb import LangDb\n\n# Initialize with API key and project ID\nclient = LangDb(api_key=\"your_api_key\", project_id=\"your_project_id\")\n```\n\n### Chat Completions\n\n```python\nmessages = [\n    {\"role\": \"system\", \"content\": \"You are a helpful assistant.\"},\n    {\"role\": \"user\", \"content\": \"Say hello!\"}\n]\n\nresponse = client.completion(\n    model=\"gemini-1.5-pro-latest\",\n    messages=messages,\n    temperature=0.7,\n    max_tokens=100\n)\n```\n\n### Thread Operations\n\n#### Get Messages\nRetrieve messages from a specific thread:\n\n```python\nmessages = client.get_messages(thread_id=\"your_thread_id\")\n\n# Access message details\nfor message in messages:\n    print(f\"Type: {message.type}\")\n    print(f\"Content: {message.content}\")\n    if message.tool_calls:\n        for tool_call in message.tool_calls:\n            print(f\"Tool: {tool_call.function.name}\")\n```\n\n#### Get Thread Cost\nGet cost and token usage information for a thread:\n\n```python\nusage = client.get_usage(thread_id=\"your_thread_id\")\nprint(f\"Total cost: ${usage.total_cost:.4f}\")\nprint(f\"Input tokens: {usage.total_input_tokens}\")\nprint(f\"Output tokens: {usage.total_output_tokens}\")\n```\n\n### Analytics\n\nGet analytics data for specific tags:\n\n```python\n# Get raw analytics data\nanalytics = client.get_analytics(\n    tags=\"model1,model2\",\n    start_time_us=None,  # Optional: defaults to 24 hours ago\n    end_time_us=None     # Optional: defaults to current time\n)\n\n# Get analytics as a pandas DataFrame\ndf = client.get_analytics_dataframe(\n    tags=\"model1,model2\",\n    start_time_us=None,\n    end_time_us=None\n)\n```\n\n## Development\n\n### Setting up the environment\n\n1. Clone the repository\n2. Create a `.env` file with your credentials:\n```bash\nLANGDB_API_KEY=\"your_api_key\"\nLANGDB_PROJECT_ID=\"your_project_id\"\n```\n\n### Running Tests\n\n```bash\npython -m unittest tests/client.py -v\n```\n\n## Publishing\n\n```bash\npoetry build\npoetry publish",
    "bugtrack_url": null,
    "license": null,
    "summary": null,
    "version": "0.2.5",
    "project_urls": null,
    "split_keywords": [],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "9eeeabd3f7bf8d70608f0da067dd41f64c0e04ceab383e070c45d7df5d705cad",
                "md5": "ec71fe6ce32fe3378062cfc431bce659",
                "sha256": "263bab13cdc4382c7d279ee4db0ecc27551b819e587604b7259af5dce16f4886"
            },
            "downloads": -1,
            "filename": "pylangdb-0.2.5-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "ec71fe6ce32fe3378062cfc431bce659",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": "<4.0,>=3.10",
            "size": 6403,
            "upload_time": "2025-02-10T04:23:40",
            "upload_time_iso_8601": "2025-02-10T04:23:40.071709Z",
            "url": "https://files.pythonhosted.org/packages/9e/ee/abd3f7bf8d70608f0da067dd41f64c0e04ceab383e070c45d7df5d705cad/pylangdb-0.2.5-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "911f68e233400633e2c2f5a5348be3fd6ecc95817869e085e8da5bcd620287ba",
                "md5": "afee082f49f2dfc83a859af3c56a14dc",
                "sha256": "ef4b54206e78c5dd63e0cb66292530ed7aed44d2e5b62702a405a1a8d4ae9082"
            },
            "downloads": -1,
            "filename": "pylangdb-0.2.5.tar.gz",
            "has_sig": false,
            "md5_digest": "afee082f49f2dfc83a859af3c56a14dc",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": "<4.0,>=3.10",
            "size": 5324,
            "upload_time": "2025-02-10T04:23:41",
            "upload_time_iso_8601": "2025-02-10T04:23:41.629036Z",
            "url": "https://files.pythonhosted.org/packages/91/1f/68e233400633e2c2f5a5348be3fd6ecc95817869e085e8da5bcd620287ba/pylangdb-0.2.5.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2025-02-10 04:23:41",
    "github": false,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "lcname": "pylangdb"
}
        
Elapsed time: 5.90655s