Skip to main content

A simple interface to models.dev, the open database of AI model specs, pricing and capabilities

Project description

llmdb

llmdb is a handy python package you can use to access the models.dev comprehensive open-source database of AI model specifications, pricing and capabilities.

The database is not curated by me and all the data is retrieved from the models.dev API which you can also use directly.

Installation

pip install llmdb

Usage

The package exposes a db singleton that lazily fetches data from the API on first access.

from llmdb import db

# Get a specific model by ID
model = db.models.get("gpt-4o")
print(f"{model.name}: {model.cost.input}$/M input tokens")

# Get a provider
provider = db.providers.get("openai")
print(f"{provider.name} has {len(provider.models)} models")

Filtering

Filter models using field equality or custom predicates.

# Filter by field values
reasoning_models = db.models.filter(reasoning=True).all()
open_source = db.models.filter(open_weights=True, reasoning=True).all()

# Filter with a custom predicate
cheap_models = db.models.filter_by(lambda m: m.cost and m.cost.input < 1.0).all()

Sorting

Sort results by any field, including nested fields using dot notation.

# Get newest models first
newest = db.models.sort_by("release_date", desc=True).all()

# Sort by input cost
by_cost = db.models.filter_by(lambda m: m.cost is not None).sort_by("cost.input").all()

Indexed Lookups

Models are indexed by provider and family for fast access.

# All models from a specific provider
openai_models = db.models.by_provider("openai").all()

# All models in a family
gpt_models = db.models.by_family("gpt").all()

Chaining Queries

All query methods return a query builder, so you can chain them.

result = (
    db.models
    .filter(reasoning=True, open_weights=True)
    .sort_by("release_date", desc=True)
    .first()
)

Query Terminators

Queries are lazy until you call a terminator method.

.all()    # Returns list of all matching items
.first()  # Returns first item or None
.count()  # Returns the count of matching items

Refreshing Data

Data is fetched once and cached. Force a refresh from the API when needed.

db.refresh()
print(f"Data fetched at: {db.fetched_at}")

Acknowledgments

This package is a wrapper around the models.dev database, created and maintained by Anomaly. All credit for the data goes to them.

Contributing

Contributions are welcome! Please open an issue or submit a pull request on GitHub.

License

This project is licensed under the MIT License. See the LICENSE file 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

llmdb-1.0.0.tar.gz (6.1 kB view details)

Uploaded Source

Built Distribution

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

llmdb-1.0.0-py3-none-any.whl (8.1 kB view details)

Uploaded Python 3

File details

Details for the file llmdb-1.0.0.tar.gz.

File metadata

  • Download URL: llmdb-1.0.0.tar.gz
  • Upload date:
  • Size: 6.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.9.2

File hashes

Hashes for llmdb-1.0.0.tar.gz
Algorithm Hash digest
SHA256 eda62db427d8975ca323a5e7840c2ab2dc5e7e742593eca9300bc878f6d48637
MD5 bb4caf6488bd4f0e87c3ea447a1183ab
BLAKE2b-256 d604d37e5d0127503605fcc71a4411c0a0b666008c0bb4f52d99658c16f0783a

See more details on using hashes here.

File details

Details for the file llmdb-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: llmdb-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 8.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.9.2

File hashes

Hashes for llmdb-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 164bef24e4edfccacca9a7a92302d7ebb768c846fdf53c486eede8c94099ebd5
MD5 3bb655a6c4a4014478f022b75b256e47
BLAKE2b-256 5581e7b1b250b5c54f582506b3f35f33124d7fd1c5d484728acc72c4632cc587

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