Skip to main content

Prerequisites

LangExtract requires Python 3.10 or higher.
1

Choose Your Installation Method

Select the installation method that best fits your needs:
  • PyPI: Recommended for most users
  • Virtual Environment: Best for isolated development
  • From Source: For contributors and advanced users
  • Docker: For containerized deployments
2

Install LangExtract

pip install langextract
Installing with -e puts the package in development mode, allowing you to modify the code without reinstalling.
3

Install Optional Dependencies

LangExtract supports optional providers and tools:
OpenAI Support
pip install langextract[openai]
All Optional Dependencies
pip install langextract[all]
Development Tools
pip install langextract[dev]
Testing Framework
pip install langextract[test]
Jupyter Notebook
pip install langextract[notebook]
4

Set Up API Key

Cloud-hosted models like Gemini require an API key. Local models with Ollama don’t need one.

Get Your API Key

Choose your provider:

Configure Your API Key

export LANGEXTRACT_API_KEY="your-api-key-here"
Never commit API keys to version control. Always use environment variables or .env files.
5

Verify Installation

Test your installation:
import langextract as lx
print(lx.__version__)  # Should print: 1.1.1

Core Dependencies

LangExtract requires the following packages:
  • google-genai (>=1.39.0) - Gemini model support
  • aiohttp (>=3.8.0) - Async HTTP requests
  • pydantic (>=1.8.0) - Data validation
  • pandas (>=1.3.0) - Data processing
  • python-dotenv (>=0.19.0) - Environment variable management
  • tqdm (>=4.64.0) - Progress bars
See the full dependency list in pyproject.toml.

Using Local LLMs with Ollama

Run LangExtract without API keys using Ollama:
1

Install Ollama

Download from ollama.com
2

Pull a Model

ollama pull gemma2:2b
3

Start Ollama Server

ollama serve
4

Use in LangExtract

import langextract as lx

result = lx.extract(
    text_or_documents=input_text,
    prompt_description=prompt,
    examples=examples,
    model_id="gemma2:2b",
    model_url="http://localhost:11434",
    fence_output=False,
    use_schema_constraints=False
)

Troubleshooting

ImportError

If you encounter import errors, ensure you’re using Python 3.10 or higher:
python --version

API Key Issues

If your API key isn’t being recognized:
  1. Check that LANGEXTRACT_API_KEY is set in your environment
  2. Verify the .env file is in your working directory
  3. Ensure you’re loading the .env file in your code if needed

Docker Issues

If Docker build fails, ensure Docker is installed and running:
docker --version

Next Steps

Now that LangExtract is installed, head to the Quick Start guide to run your first extraction.

Build docs developers (and LLMs) love