Skip to main content

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.

Metadata

Release files for langchainer 0.0.5

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

Source distribution (sdist)

Source distribution for langchainer 0.0.5
File Size Uploaded
langchainer-0.0.5.tar.gz 20.0 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for langchainer 0.0.5
File Interpreter ABI Platform
langchainer-0.0.5-py3-none-any.whl Python 3 none any Details

Total release size: 40.8 kB

Release files / langchainer-0.0.5.tar.gz

Download URL langchainer-0.0.5.tar.gz
Size 20.0 kB
Tags Source
SHA-256 checksum
How to use checksums
48ae62872d31f3354471e73be96e360344c8a28de3751d8ae0851c484802c095
BLAKE2b-256 checksum
How to use checksums
a4bce50cf610b1417b049563ab65cb3b39982abaef04e0dc286d3cb3f44eba3e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.12.9

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Feb 28, 2025.

Transparency log

Release files / langchainer-0.0.5-py3-none-any.whl

Download URL langchainer-0.0.5-py3-none-any.whl
Size 20.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
f5bd9460fd6866aabebb6ba50fcfe62263e7ad32bd36de46f12b8af153c9d452
BLAKE2b-256 checksum
How to use checksums
022942bc95d8a504df887807e931e312c11894feac982d1e2968ff923bd3984f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.12.9

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Feb 28, 2025.

Transparency log

Release history Release notifications | RSS feed

This release

0.0.5 This release

2 release files

0.0.2

2 release files

0.0.1

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