Skip to content

Commit 9c47b34

Browse files
authored
Merge pull request #11 from google/fix/libmagic-dependency-issue
2 parents 4fe7580 + e696a48 commit 9c47b34

File tree

4 files changed

+41
-1
lines changed

4 files changed

+41
-1
lines changed

Dockerfile

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# Production Dockerfile for LangExtract with libmagic support
2+
FROM python:3.10-slim
3+
4+
# Install system dependencies including libmagic
5+
RUN apt-get update && apt-get install -y --no-install-recommends \
6+
libmagic1 \
7+
&& rm -rf /var/lib/apt/lists/*
8+
9+
# Set working directory
10+
WORKDIR /app
11+
12+
# Install LangExtract from PyPI
13+
RUN pip install --no-cache-dir langextract
14+
15+
# Set default command
16+
CMD ["python"]

README.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,12 @@ pip install -e ".[dev]"
181181
pip install -e ".[test]"
182182
```
183183

184+
### Docker
185+
186+
```bash
187+
docker build -t langextract .
188+
docker run --rm -e LANGEXTRACT_API_KEY="your-api-key" langextract python your_script.py
189+
```
184190

185191
## API Key Setup for Cloud Models
186192

@@ -297,6 +303,12 @@ Or reproduce the full CI matrix locally with tox:
297303
tox # runs pylint + pytest on Python 3.10 and 3.11
298304
```
299305

306+
## Troubleshooting
307+
308+
**libmagic error**: If you see "failed to find libmagic", install with `pip install langextract[full]` or install system dependencies:
309+
- Ubuntu/Debian: `sudo apt-get install libmagic1`
310+
- macOS: `brew install libmagic`
311+
300312
## Disclaimer
301313

302314
This is not an officially supported Google product. If you use

langextract/__init__.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,13 @@
1616

1717
from __future__ import annotations
1818

19+
# Ensure libmagic is available before langfun imports python-magic.
20+
# pylibmagic provides pre-built binaries that python-magic needs.
21+
try:
22+
import pylibmagic # noqa: F401 (side-effect import)
23+
except ImportError:
24+
pass
25+
1926
from collections.abc import Iterable, Sequence
2027
import os
2128
from typing import Any, Type, TypeVar, cast

pyproject.toml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ build-backend = "setuptools.build_meta"
1818

1919
[project]
2020
name = "langextract"
21-
version = "1.0.0"
21+
version = "1.0.1"
2222
description = "LangExtract: A library for extracting structured data from language models"
2323
readme = "README.md"
2424
requires-python = ">=3.10"
@@ -41,6 +41,7 @@ dependencies = [
4141
"pydantic>=1.8.0",
4242
"python-dotenv>=0.19.0",
4343
"python-magic>=0.4.27",
44+
"pylibmagic>=0.5.0",
4445
"requests>=2.25.0",
4546
"tqdm>=4.64.0",
4647
"typing-extensions>=4.0.0"
@@ -64,6 +65,10 @@ test = [
6465
"pytest>=7.4.0",
6566
"tomli>=2.0.0"
6667
]
68+
full = [
69+
"python-magic>=0.4.27",
70+
"pylibmagic>=0.5.0",
71+
]
6772

6873
[tool.setuptools]
6974
packages = ["langextract"]

0 commit comments

Comments
 (0)