Best of 4 worlds [LangChain, LiteLLM, Instructor, Rich] in 1 helper + 1 client with easy debugging.
Project description
LangChainer
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 isINFO.RICH_LOGGING_ENABLED: Enable or disable Rich logging (trueorfalse). Default isfalse.SYNTAX_THEME: Set the syntax highlighting theme for Rich (see available themes). Default isgithub-dark.MARKDOWN_PROMPT: Enable or disable Markdown rendering for prompt content (default istrue).MARKDOWN_RESPONSE: Enable or disable Markdown rendering for LLM response content (default istrue).SHOW_PROMPT_VALUES: Enable or disable the display of prompt variable values in the log output (default istrue).PANEL_PADDING: Set the padding for Rich panels (integer or tuple, default is0).
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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file langchainer-0.0.2.tar.gz.
File metadata
- Download URL: langchainer-0.0.2.tar.gz
- Upload date:
- Size: 20.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4fc8c0751f9aa6b7a16c0f4902d367595993ec81ecb5748e989ca659da490c39
|
|
| MD5 |
95958c4fb99e517261890c275a220186
|
|
| BLAKE2b-256 |
ff37face4ae1912ba4dd7b64b0af807169b2325ae3f428f614a5ad889a7516fd
|
Provenance
The following attestation bundles were made for langchainer-0.0.2.tar.gz:
Publisher:
publish.yml on saintd/langchainer
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
langchainer-0.0.2.tar.gz -
Subject digest:
4fc8c0751f9aa6b7a16c0f4902d367595993ec81ecb5748e989ca659da490c39 - Sigstore transparency entry: 175448143
- Sigstore integration time:
-
Permalink:
saintd/langchainer@7836d0dc640952dfbac5e6c2a56f28a739004f48 -
Branch / Tag:
refs/tags/v0.0.4 - Owner: https://github.com/saintd
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@7836d0dc640952dfbac5e6c2a56f28a739004f48 -
Trigger Event:
push
-
Statement type:
File details
Details for the file langchainer-0.0.2-py3-none-any.whl.
File metadata
- Download URL: langchainer-0.0.2-py3-none-any.whl
- Upload date:
- Size: 21.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0211b56989ad5a03a587d4a67571e151aca42ad6b1804ae45f21fac50e504d55
|
|
| MD5 |
95a9db5c1f4928f7c63f46e8868dfd28
|
|
| BLAKE2b-256 |
c69cf70639ebc11717ba94e1bfe26685fd83dc6df1fb9793e1244847378059c2
|
Provenance
The following attestation bundles were made for langchainer-0.0.2-py3-none-any.whl:
Publisher:
publish.yml on saintd/langchainer
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
langchainer-0.0.2-py3-none-any.whl -
Subject digest:
0211b56989ad5a03a587d4a67571e151aca42ad6b1804ae45f21fac50e504d55 - Sigstore transparency entry: 175448146
- Sigstore integration time:
-
Permalink:
saintd/langchainer@7836d0dc640952dfbac5e6c2a56f28a739004f48 -
Branch / Tag:
refs/tags/v0.0.4 - Owner: https://github.com/saintd
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@7836d0dc640952dfbac5e6c2a56f28a739004f48 -
Trigger Event:
push
-
Statement type: