Skip to main content

LLM powered Python

Project description

Nerif

Program with both Python and Natural Language.

LLMs can be tricky to work with. They sometimes give overly formal responses or get confused when they're unsure, making them challenging to use in real applications.

That's why we built Nerif - a simple tool that connects LLMs with Python code. We want to make it better than existing tools like Langchain and Dify.

Nerif helps you:

  • Control exactly how LLMs work in your code
  • Convert LLM responses into usable data formats
  • Track performance with metrics like cost and success rate
  • Build multi-agent workflows with observable execution traces

Our goal is to make LLMs easier to use for developers, turning complex AI capabilities into practical programming tools.

How to install

Pre-requisite

  • Python >= 3.10
  • Environment variable OPENAI_API_KEY or other LLM API keys, for more details, see here
  • Set default model and embedding model with NERIF_DEFAULT_LLM_MODEL and NERIF_DEFAULT_EMBEDDING_MODEL, for more details, see here

Example:

export OPENAI_API_KEY=`your_api_key`
export NERIF_DEFAULT_LLM_MODEL=gpt-4o
export NERIF_DEFAULT_EMBEDDING_MODEL=text-embedding-3-small

Install

pip install nerif

Optional feature groups:

pip install "nerif[rag]"       # NumPy vector store for RAG
pip install "nerif[img-gen]"   # Image generation (Pillow)
pip install "nerif[viz]"       # HTML trace reports (Jinja2)
pip install "nerif[otel]"      # OpenTelemetry adapter

For local development setup, see docs/setup_guide.md.

QuickStart

from nerif.core import nerif
from nerif.model import SimpleChatModel

model = SimpleChatModel()
# Default model is `gpt-4o`

# Use nerif judge "natural language statement"
if nerif("the sky is blue"):
    print("True")
else:
    # Call a simple model
    print("No", end=", ")
    print(model.chat("what is the color of the sky?"))

Changelog

v1.4.0

  • Opt-in nerif.observability package for workflow tracing, trace storage, recording, budget controls, dashboards, exports, and reports
  • Agent and orchestrator tracing integration for multi-agent workflows
  • Callback coverage for LLM, tool, fallback, retry, and memory events
  • Public observability exports and optional viz / otel extras

v1.3.0

  • Async agent: NerifAgent.arun() with concurrent tool execution
  • Model fallback chain: automatic failover on transient errors
  • Callback/hook system: 7 event types for observability
  • PromptTemplate: variable substitution, defaults, conditional sections
  • Rate limiting: per-model/provider request throttling
  • Enhanced ASR: Transcriber with language/format/translate support
  • Enhanced TTS: Synthesizer with voice/speed/format/file output
  • Streaming now supports token counting and retry

v1.2.0

  • ConversationMemory: sliding window with auto-summarization
  • NerifTokenCounter: latency, cost, success rate tracking
  • Lightweight RAG with NumpyVectorStore
  • Custom exception hierarchy (NerifError, ProviderError, etc.)
  • CLI tools: nerif check, nerif test-model, nerif models

v1.1.0

  • Streaming and async support (stream_chat, achat)
  • Pydantic structured output (response_model=)
  • Retry with exponential backoff (RetryConfig)
  • Optional embedding model
  • Multi-provider routing (OpenAI, Anthropic, Gemini, Ollama, etc.)

Documentation

More detailed documentation is on the official website.

License

Nerif is licensed under the GNU General Public License v3.0.

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

nerif-1.4.0.tar.gz (7.6 MB view details)

Uploaded Source

Built Distribution

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

nerif-1.4.0-py3-none-any.whl (126.2 kB view details)

Uploaded Python 3

File details

Details for the file nerif-1.4.0.tar.gz.

File metadata

  • Download URL: nerif-1.4.0.tar.gz
  • Upload date:
  • Size: 7.6 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for nerif-1.4.0.tar.gz
Algorithm Hash digest
SHA256 5e2f896e4d02bc85102876755539533a86a2af86d40e1394ddb1641056051a20
MD5 330b0b3e9e613f7652a88e6607d5f552
BLAKE2b-256 cf4a8df3b40ed400919f0e83cb971661ed4ad00141d0e5c17782cd7ecd508802

See more details on using hashes here.

Provenance

The following attestation bundles were made for nerif-1.4.0.tar.gz:

Publisher: release.yml on Nerif-AI/Nerif

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

File details

Details for the file nerif-1.4.0-py3-none-any.whl.

File metadata

  • Download URL: nerif-1.4.0-py3-none-any.whl
  • Upload date:
  • Size: 126.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for nerif-1.4.0-py3-none-any.whl
Algorithm Hash digest
SHA256 606d7caa020e2c3753b877221a53024b59c6f41e855ab86c5495e2e8d13a972f
MD5 2f600e86d0ba494039ef67f1de6faa12
BLAKE2b-256 6333d0b807a8a2f857e511823f7e28f4ec10d48a4eb966e3828ff946eb93f1e3

See more details on using hashes here.

Provenance

The following attestation bundles were made for nerif-1.4.0-py3-none-any.whl:

Publisher: release.yml on Nerif-AI/Nerif

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