llama-cpp-python
Python bindings for the llama.cpp library
What it is and what it does
llama-cpp-python wraps the llama.cpp C library to bring efficient local language model inference to Python. It provides both a low-level ctypes interface to the C API and a high-level Python API that mimics OpenAI's completion endpoints, making it easy to integrate into existing workflows. The package supports multiple hardware acceleration backends including CUDA, Metal, ROCm, Vulkan, and CPU-only inference, with pre-built wheels available to avoid compilation overhead.
The library is designed for developers who want to run large language models on their own hardware without cloud dependencies. It includes an OpenAI-compatible web server for local API access, function calling support, vision model capabilities, and multi-model serving. Installation requires a C compiler and can be complex depending on your target hardware backend, but active maintenance and comprehensive documentation help mitigate setup friction.
Use it for:
- Run private language models locally without sending data to cloud APIs
- Build OpenAI-compatible applications that work offline or on restricted networks
- Integrate local inference into existing application frameworks for RAG or agent workflows
- Deploy a local code completion server for development environments
- Serve multiple models simultaneously via the built-in web server for multi-tenant inference
- Accelerate inference on specific hardware (GPU, Apple Silicon) for production workloads
Worth the install?
AI-flagged interpretation of the facts on this page — verify before relying
Python bindings for llama.cpp that enable running large language models locally with CPU or GPU acceleration, offering both low-level C API access and high-level text completion APIs compatible with OpenAI, LangChain, and LlamaIndex.
Yes, with conditions. Install if you need local language model inference with hardware acceleration and can handle a non-trivial build process. The package is actively maintained, has no known vulnerabilities, and integrates well with popular frameworks. However, expect high install friction due to C compilation requirements—use pre-built wheels where available to reduce setup complexity. Not recommended if you need a quick, zero-configuration solution.
Install
llama-cpp-python on PyPI
pip
pip install llama-cpp-pythonuv
uv add llama-cpp-pythonpoetry
poetry add llama-cpp-pythonInstalling llama-cpp-python
Before you install
Installation requires a C compiler and builds llama.cpp from source, which is computationally intensive and may fail without proper toolchain setup. Pre-built wheels are available for multiple backends to reduce build friction. The package is actively maintained with recent releases.
License in practice
MIT license permits commercial use, modification, and distribution with minimal restrictions, making it suitable for proprietary projects.
Quickstart
pip install llama-cpp-python
from llama_cpp_python import Llama
llm = Llama(model_path="/path/to/model.gguf")
response = llm("Hello, how are you?")
Requires a C compiler (gcc/clang on Linux, Visual Studio/MinGW on Windows, Xcode on macOS) and a compatible GGUF-format model file; build may fail without proper toolchain configuration.
Verify before relying
- Whether pre-built wheels significantly reduce installation time compared to source builds
- Performance characteristics across different hardware backends (CPU vs CUDA vs Metal vs ROCm)
- Memory requirements for running models of different sizes
- Latency and throughput benchmarks for typical inference workloads
Package facts
| License | MIT (permissive) |
| Python support | supports the current Python release (>=3.8) |
| Install friction | high — source build required |
| Runtime dependencies | 4 — typing-extensions, numpy, diskcache, jinja2 |
| Maintenance | actively maintained — 33 days since the last release |
| Last repo commit | |
| First released | |
| Downloads | 732,904/month — #5,200 on PyPI (30-day window, as of 2026-08-14) |
| Known vulnerabilities | none known (OSV.dev, checked 2026-08-14) |
Evidence: llama_cpp_python-0.3.34.tar.gz
Tags
More Artificial Intelligence packages
LiteLLM provides a unified Python interface to…
permissive · top 100 on PyPI
huggingface-hubClient library and CLI tool for downloading,…
permissive · top 100 on PyPI
langchainLangChain provides a framework for building…
permissive · top 1,000 on PyPI
hf-xethf-xet provides chunk-based deduplication and…
permissive · top 1,000 on PyPI
tokenizersTokenizers converts raw text into token…
permissive · top 1,000 on PyPI
transformersTransformers provides a unified framework for…
permissive · top 1,000 on PyPI
ggufReads and writes binary files in the GGUF (GGML…
permissive · top 5,000 on PyPI
llama-index-llms-openai-likeProvides a thin wrapper to use…
permissive · top 15,000 on PyPI
abstract-hugpy-devA self-hosted LLM console and OpenAI-compatible…
unclear · top 15,000 on PyPI
llama-index-llms-langchainBridges LlamaIndex with LangChain LLM…
permissive · top 15,000 on PyPI
ipex-llmAccelerates large language model inference on…
permissive · top 15,000 on PyPI
llama-index-program-openaiIntegrates OpenAI-powered program synthesis…
permissive · top 5,000 on PyPI
sgl-kernelsgl-kernel provides optimized CUDA compute…
permissive · top 15,000 on PyPI
sglang-kernelsglang-kernel provides optimized CUDA compute…
permissive · top 15,000 on PyPI
llama-index-agent-openaiIntegrates OpenAI language models with…
permissive · top 5,000 on PyPI
llama-index-multi-modal-llms-openaiIntegrates OpenAI's multi-modal language models…
permissive · top 5,000 on PyPI