llama-cpp-python
Python bindings for llama.cpp with OpenAI-compatible API server.
About
Python bindings for Georgi Gerganov's llama.cpp turn that C++ inference library into something installable with pip and usable from ordinary Python code. llama-cpp-python exposes three layers: low-level ctypes bindings to the C API, a high-level interface for text and chat completion, and an OpenAI-compatible web server that works as a drop-in replacement for hosted APIs. It supports function and tool calling in the OpenAI format, multimodal input through models such as LLaVA and Moondream, JSON schema constrained output, speculative decoding with draft models, and embedding generation. Builds compile llama.cpp from source, with CMake flags enabling CUDA, Metal, ROCm, Vulkan, SYCL, or OpenBLAS backends, and models can be pulled directly from the Hugging Face Hub. The library integrates with LangChain and LlamaIndex and is released under the MIT license, making it a common foundation for local assistants and privacy-sensitive deployments.
Should you use llama-cpp-python?
Pick it when
Pick llama-cpp-python when a Python application needs to load GGUF models in-process, use JSON-schema output or tool calling, or plug local models into LangChain or LlamaIndex without running a separate server.
Look elsewhere when
Skip it if you just need a local server, since llama.cpp ships its own and Ollama is easier. Source builds with CUDA or Metal flags can be fiddly, and you depend on the bindings keeping pace with upstream llama.cpp.
Alternatives to llama-cpp-python
- llama.cpp
The upstream engine and its built-in server get new models and backends first, but you call it over HTTP or C rather than from Python.
- Ollama
Easier install and model management with an official Python library, but it runs as a separate service instead of in-process.
- mistral.rs
Rust engine with a Python API and wider quantization options such as GPTQ, AWQ, and in-situ conversion, but a smaller community.
- LocalAI
A Docker-packaged OpenAI-compatible server covering chat, images, and audio, better when other services rather than Python code consume models.
Reviews (0)
Leave a Review
No reviews yet. Be the first to review!
Details
- Category
- LLM Inference & Serving
- Price
- Free
- Platform
- Local/Desktop
- Difficulty
- Easy (2/5)
- License
- MIT
- Added
- Apr 3, 2026