Skip to main content

Identify pills and medications from images using AI vision models

Project description

pill-id

CI PyPI Python License: MIT

"What pill is this?" -- Identify pills and medications from images using AI vision models.

$ pill-id identify mystery_pill.jpg

Extracted Features:
  Color: white
  Shape: capsule
  Imprint (front): TYLENOL 500

Top 3 Matches:
  1. Tylenol Extra Strength (Acetaminophen) 500mg
     Manufacturer: Johnson & Johnson
     Confidence: 92%

  2. Tylenol (Acetaminophen) 325mg
     Manufacturer: Johnson & Johnson
     Confidence: 58%

Disclaimer: This tool is for informational purposes only.
Always verify medication identity with a pharmacist.

Why?

Unidentified pills are a real safety problem. Every year, poison control centers receive thousands of calls about unknown medications found in homes, on the ground, or mixed up in pill organizers.

Existing pill identification tools are either closed-source, require paid subscriptions, or rely on outdated databases. pill-id is the first open-source pill identification library that combines state-of-the-art AI vision models with an embedded medication database.

How It Works

pill-id uses a two-phase approach:

  1. Vision AI Extraction: Send a pill image to GPT-4V or Claude Vision to extract visual features (color, shape, imprint text, scoring marks, coating type)
  2. Database Matching: Match extracted features against an embedded database of 200+ common medications, scored by confidence

This approach is more practical than training a custom image classifier because:

  • No training data needed
  • Works immediately with any new pill
  • Leverages state-of-the-art vision models
  • Easy to extend the database

Quick Start

Installation

pip install pill-id

For Anthropic Claude support:

pip install pill-id[anthropic]

Python API

from pill_id import PillIdentifier

identifier = PillIdentifier(
    provider="openai",      # or "anthropic"
    api_key="sk-...",       # or set OPENAI_API_KEY env var
)

# Identify from a file
result = identifier.identify("pill_photo.jpg")
print(result.matches[0].name)          # "Acetaminophen 500mg"
print(result.matches[0].confidence)    # 0.92
print(result.extracted_features.color) # "white"

# Identify from URL
result = identifier.identify("https://example.com/pill.jpg")

# Identify from bytes
with open("pill.jpg", "rb") as f:
    result = identifier.identify(f.read())

# Batch identification
results = identifier.identify_batch(["pill1.jpg", "pill2.jpg"])

CLI

# Identify a pill
pill-id identify photo.jpg
pill-id identify photo.jpg --provider anthropic --top 5
pill-id identify photo.jpg --json-output

# Search the database
pill-id search --imprint "M 357" --color white
pill-id search --imprint "TYLENOL" --json-output

# Database stats
pill-id database

Supported Providers

Provider Model Env Variable
OpenAI GPT-4o (default) OPENAI_API_KEY
Anthropic Claude Sonnet (default) ANTHROPIC_API_KEY

Database

The embedded database includes 200+ medications:

  • 100+ top prescribed US medications (by visual appearance)
  • 30+ common OTC medications (Tylenol, Advil, Aleve, etc.)
  • 50+ popular supplements (Vitamin D, Fish Oil, Magnesium, etc.)
  • 50 manufacturer imprint patterns (M = Mylan, IP = Amneal, etc.)

Custom Database

You can supply your own pill database:

from pill_id import PillIdentifier
from pill_id.models import PillDatabaseEntry

custom_db = [
    PillDatabaseEntry(
        name="My Custom Med",
        generic_name="Customamine",
        strength="50mg",
        manufacturer="Custom Pharma",
        imprint="CP 50",
        color="blue",
        shape="round",
    ),
]

identifier = PillIdentifier(
    provider="openai",
    api_key="sk-...",
    custom_database=custom_db,
)

Confidence Scoring

Matches are scored based on multiple features:

Feature Weight
Exact imprint match +0.50
Partial imprint match +0.25
Color match +0.15
Shape match +0.15
Manufacturer code match +0.10
Scoring/coating match +0.10

Safety

IMPORTANT: This tool is for informational purposes only. Always verify medication identity with a pharmacist or healthcare provider. Never take medication based solely on AI identification.

pill-id includes built-in safety features:

  • Every result includes a disclaimer
  • Low-confidence matches (< 70%) trigger explicit warnings
  • Multiple ambiguous matches are flagged
  • Controlled substances are flagged with additional warnings
  • The library never suggests dosage or usage information

Accuracy Notes

  • Best results come from clear, well-lit photos of a single pill against a contrasting background
  • Imprint text is the strongest identifier -- if the model can read the imprint, accuracy is high
  • Color and shape alone are unreliable -- many different medications share the same appearance
  • Results should always be verified by a pharmacist
  • The database covers common US medications; international medications may not be included

Development

# Clone and install
git clone https://github.com/pillright/pill-id.git
cd pill-id
pip install -e ".[dev,anthropic]"

# Run tests (no API keys needed)
pytest

# Lint
ruff check src/ tests/

Related Projects

Contributing

Contributions are welcome! Please see our contributing guidelines:

  1. Fork the repository
  2. Create a feature branch (git checkout -b feature/my-feature)
  3. Add tests for any new functionality
  4. Ensure all tests pass (pytest)
  5. Submit a pull request

License

MIT License. See LICENSE for details.

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

pill_id-0.1.0.tar.gz (31.7 kB view details)

Uploaded Source

Built Distribution

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

pill_id-0.1.0-py3-none-any.whl (32.0 kB view details)

Uploaded Python 3

File details

Details for the file pill_id-0.1.0.tar.gz.

File metadata

  • Download URL: pill_id-0.1.0.tar.gz
  • Upload date:
  • Size: 31.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.3

File hashes

Hashes for pill_id-0.1.0.tar.gz
Algorithm Hash digest
SHA256 8046b02fe7211f325a627a04a53d48d5c2112e4c08b5a86824e451c1edad7be1
MD5 6a513b2116eccb84d0630a4fd9955238
BLAKE2b-256 1f7c3347b24486c5d40858b5b03f015f3ec7c02fbf16905e3ef539619bb79e4a

See more details on using hashes here.

File details

Details for the file pill_id-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: pill_id-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 32.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.3

File hashes

Hashes for pill_id-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 c8553b12b808ddf6049d8f147aeffb9acc262a7d8b1457a7cfe7df95e63da1be
MD5 0bc024b8bca36d889ed5a54314e73f02
BLAKE2b-256 bb1a9faf51e3ea60e65de8cda147e555f364276ef4cf4e916fd436f8db9a08d2

See more details on using hashes here.

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