Metadata-Version: 2.3
Name: langchainer
Version: 0.0.2
Summary: Best of 4 worlds [LangChain, LiteLLM, Instructor, Rich] in 1 helper + 1 client with easy debugging.
License: MIT License
         
         Copyright (c) 2024 Pavel Mironov
         
         Permission is hereby granted, free of charge, to any person obtaining a copy
         of this software and associated documentation files (the "Software"), to deal
         in the Software without restriction, including without limitation the rights
         to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
         copies of the Software, and to permit persons to whom the Software is
         furnished to do so, subject to the following conditions:
         
         The above copyright notice and this permission notice shall be included in all
         copies or substantial portions of the Software.
         
         THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
         IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
         FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
         AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
         LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
         OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
         SOFTWARE.
Keywords: llm,langchain,litellm,instructor,rich,ai,machine-learning,debugging,openai,mistral,together,anthropic,openrouter,google_genai
Author: Pavel Mironov
Author-email: mironov.pv@gmail.com
Requires-Python: >=3.10
Classifier: Development Status :: 3 - Alpha
Classifier: Intended Audience :: Developers
Classifier: Topic :: Software Development :: Libraries :: Python Modules
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Operating System :: OS Independent
Requires-Dist: langchain (>=0.3.13)
Requires-Dist: langchain-core (>=0.3.28)
Requires-Dist: pydantic (>=2.10.4)
Project-URL: Bug Tracker, https://github.com/saintd/langchainer/issues
Project-URL: Homepage, https://github.com/saintd/langchainer
Description-Content-Type: text/markdown

# LangChainer

[![PyPI version](https://badge.fury.io/py/langchainer.svg)](https://badge.fury.io/py/langchainer)
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)


LangChainer is a lightweight Python library that streamlines your interactions with Large Language Models (LLMs) by bringing together the best of **LangChain**, **LiteLLM**, **Instructor**, and **Rich** into a single, easy-to-use package. It provides a unified interface for working with various LLM providers, simplifies structured output handling, and enhances debugging with beautiful, informative logging.
Offers incredible simplicity for LLM interaction and enhanced debugging, especially with structured output.

**Key Features:**

*   **Simplified LLM Interaction:** One helper (`init_llm`) and one client (`LLMClient`) to rule them all.
*   **Unified Interface:**  Work seamlessly with multiple LLM providers (OpenAI, Mistral, Together, Anthropic, OpenRouter, Google Gemini) using a consistent API.
*   **Structured Output:** Easily define and receive structured data from LLMs using Pydantic models.
*   **Enhanced Debugging:** Leverage the power of [Rich](https://github.com/Textualize/rich) for visually appealing and informative logs, making debugging a breeze.
*   **Rate Limiting & Retries:** Built-in rate limiting and configurable retry mechanisms for robust LLM interactions.
*   **Modern Python:** Developed for Python 3.10+ with extensive type hinting and a clean, modern codebase.

**Installation**

Install the core `langchainer` package:

```bash
pip install langchainer
```

For enhanced debugging with Rich, install the `[rich]` extra:

```bash
pip install langchainer[rich]
```

To use a specific LLM provider, install the corresponding provider package in the standard way (e.g. `pip install langchain_openai` for OpenAI) or use the shortcut extras:
```bash
pip install langchainer[openai]  # For OpenAI
pip install langchainer[mistral] # For Mistral
pip install langchainer[anthropic] # For Anthropic
...
pip install langchainer[rich,mistral] # For Mistral with Rich. And so on.
```

**Basic Usage**

```dotenv
# .env
OPENAI_API_KEY="YOUR_API_KEY"
RICH_LOGGING_ENABLED=true
```

```python
import logging
from pydantic import BaseModel
from langchain_core.prompts import ChatPromptTemplate

from langchainer import LLMClient

# Optional: Enable Rich logging
# from langchainer import init_logger
# init_logger(log_level=logging.DEBUG, use_rich=True)

# Initialize the client with your chosen model
client = LLMClient("mistral/mistral-small-latest")  # Or "openai/gpt-3.5-turbo", etc.

# --- Example 1: Simple String Prompt ---
response = await client.run("What is the meaning of life?")
print(response)

# --- Example 2: Using a ChatPromptTemplate ---
template = ChatPromptTemplate.from_template("Tell me a joke about {topic}")
response = await client.run(template, {"topic": "programming"})
print(response)


# --- Example 3: Structured Output ---
class Joke(BaseModel):
    setup: str
    punchline: str


response = client.run_sync("Tell me a joke about technology", output_schema=Joke)
print(response.setup)
print(response.punchline)

# --- Example 4: Async usage with structured output and XML tags ---
import asyncio


async def main():
    class Fact(BaseModel):
        fact: str

    response = await client.run(
        "Tell me a fact about {subject}",
        {"subject": "the ocean"},
        output_schema=Fact,
        system_message="You are a helpful assistant.",
        apply_xml_tags=True
    )
    print(response)


asyncio.run(main())
```

**Configuration**

You can configure `langchainer`'s logging behavior using environment variables:

*   **`LOG_LEVEL`:**  Set the logging level (e.g., `DEBUG`, `INFO`, `WARNING`, `ERROR`, `CRITICAL`). Default is `INFO`.
*   **`RICH_LOGGING_ENABLED`:** Enable or disable Rich logging (`true` or `false`). Default is `false`.
*   **`SYNTAX_THEME`:**  Set the syntax highlighting theme for Rich (see [available themes](https://pygments.org/styles/)). Default is `github-dark`.
*   **`MARKDOWN_PROMPT`:** Enable or disable Markdown rendering for prompt content (default is `true`).
*   **`MARKDOWN_RESPONSE`:** Enable or disable Markdown rendering for LLM response content (default is `true`).
*   **`SHOW_PROMPT_VALUES`:**  Enable or disable the display of prompt variable values in the log output (default is `true`).
*   **`PANEL_PADDING`:** Set the padding for Rich panels (integer or tuple, default is `0`).

**Documentation**

For more advanced usage, detailed API documentation, and examples, please visit our GitHub repository.

**Contributing**

Contributions are welcome! Please see our [Contribution Guidelines](CONTRIBUTING.md) for details.

**License**

`langchainer` is released under the MIT License. See the [LICENSE](LICENSE) file for details.

**Disclaimer**

`langchainer` is an independent project and is not officially affiliated with LangChain.


