Skip to main content

Best of 4 worlds [LangChain, LiteLLM, Instructor, Rich] in 1 helper + 1 client with easy debugging.

Project description

LangChainer

PyPI version License: 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 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:

pip install langchainer

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

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:

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

# .env
OPENAI_API_KEY="YOUR_API_KEY"
RICH_LOGGING_ENABLED=true
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). 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 for details.

License

langchainer is released under the MIT License. See the LICENSE file for details.

Disclaimer

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

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

langchainer-0.0.5.tar.gz (20.0 kB view details)

Uploaded Source

Built Distribution

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

langchainer-0.0.5-py3-none-any.whl (20.8 kB view details)

Uploaded Python 3

File details

Details for the file langchainer-0.0.5.tar.gz.

File metadata

  • Download URL: langchainer-0.0.5.tar.gz
  • Upload date:
  • Size: 20.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for langchainer-0.0.5.tar.gz
Algorithm Hash digest
SHA256 48ae62872d31f3354471e73be96e360344c8a28de3751d8ae0851c484802c095
MD5 fdce5fd7048ff3682edc6a5b568cfff3
BLAKE2b-256 a4bce50cf610b1417b049563ab65cb3b39982abaef04e0dc286d3cb3f44eba3e

See more details on using hashes here.

Provenance

The following attestation bundles were made for langchainer-0.0.5.tar.gz:

Publisher: publish.yml on saintd/langchainer

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file langchainer-0.0.5-py3-none-any.whl.

File metadata

  • Download URL: langchainer-0.0.5-py3-none-any.whl
  • Upload date:
  • Size: 20.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for langchainer-0.0.5-py3-none-any.whl
Algorithm Hash digest
SHA256 f5bd9460fd6866aabebb6ba50fcfe62263e7ad32bd36de46f12b8af153c9d452
MD5 e9c9dffcd759587cd963df351ce94cdd
BLAKE2b-256 022942bc95d8a504df887807e931e312c11894feac982d1e2968ff923bd3984f

See more details on using hashes here.

Provenance

The following attestation bundles were made for langchainer-0.0.5-py3-none-any.whl:

Publisher: publish.yml on saintd/langchainer

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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