llm-prices 1.2.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- llm_prices-1.2.0/.gitignore +6 -0
- llm_prices-1.2.0/CHANGELOG.md +24 -0
- llm_prices-1.2.0/LICENSE +21 -0
- llm_prices-1.2.0/PKG-INFO +44 -0
- llm_prices-1.2.0/pyproject.toml +64 -0
- llm_prices-1.2.0/src/llm_prices/__init__.py +59 -0
- llm_prices-1.2.0/src/llm_prices/_core.py +871 -0
- llm_prices-1.2.0/src/llm_prices/_data.py +150 -0
- llm_prices-1.2.0/src/llm_prices/py.typed +0 -0
- llm_prices-1.2.0/tests/test_cost.py +363 -0
- llm_prices-1.2.0/tests/test_lookup.py +302 -0
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
All notable changes to the `llm-prices` Python package. Versions follow the Rust crate's:
|
|
4
|
+
price-data-only updates are patch releases, new API is a minor release.
|
|
5
|
+
|
|
6
|
+
## [1.2.0] - 2026-11-15
|
|
7
|
+
|
|
8
|
+
First release on PyPI. Same table as the Rust crate 1.2.0 (generated 2026-11-14, 136 rows:
|
|
9
|
+
Anthropic, OpenAI, Google, DeepSeek, Mistral, xAI, Cohere, Groq, Together AI, Fireworks AI).
|
|
10
|
+
|
|
11
|
+
### Added
|
|
12
|
+
|
|
13
|
+
- `lookup(model)`: the Rust crate's id handling (aliases, any ASCII case, provider prefixes,
|
|
14
|
+
Bedrock and Vertex ids, dated snapshots, `-latest`), with the same answers.
|
|
15
|
+
- `lookup_provider(provider, model)` and `Provider` (`Provider.parse`, `rows`, `lookup`,
|
|
16
|
+
`fallback_providers`), so a host's price is never taken for another host's.
|
|
17
|
+
- `Price` (frozen dataclass) with `rate`, `rate_str` (the exact text in prices.json),
|
|
18
|
+
`rate_decimal`, `long_context_rate_str`, `provider_kind`, plus `name` and `note`.
|
|
19
|
+
- `Price.cost(input, output)` and `Price.cost_usage(usage)` with cache reads, 5m and 1h cache
|
|
20
|
+
writes, batch discounts and the long-context switch. Float results equal the Rust crate's
|
|
21
|
+
bit for bit; `exact=True` (or `cost_decimal` / `cost_usage_decimal`) returns
|
|
22
|
+
`decimal.Decimal`.
|
|
23
|
+
- `Usage`, `CostBreakdown`, `DecimalCostBreakdown`, `LongContext`, `all_prices()`,
|
|
24
|
+
`GENERATED`. Type hints throughout (`py.typed`).
|
llm_prices-1.2.0/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Matthew Busel
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
Metadata-Version: 2.5
|
|
2
|
+
Name: llm-prices
|
|
3
|
+
Version: 1.2.0
|
|
4
|
+
Summary: Dated, source-cited LLM API prices (Anthropic, OpenAI, Gemini, DeepSeek, Mistral, xAI, Groq, Together, Fireworks, Cohere) per 1M tokens, with provider-aware model-id lookup and exact decimal costs. Zero dependencies.
|
|
5
|
+
Project-URL: Homepage, https://github.com/Mattbusel/llm-prices
|
|
6
|
+
Project-URL: Source, https://github.com/Mattbusel/llm-prices/tree/main/python
|
|
7
|
+
Project-URL: Changelog, https://github.com/Mattbusel/llm-prices/blob/main/python/CHANGELOG.md
|
|
8
|
+
Project-URL: Issues, https://github.com/Mattbusel/llm-prices/issues
|
|
9
|
+
Author: Matthew Busel
|
|
10
|
+
License-Expression: MIT
|
|
11
|
+
License-File: LICENSE
|
|
12
|
+
Keywords: anthropic,cost,gemini,llm,openai,pricing,tokens
|
|
13
|
+
Classifier: Development Status :: 5 - Production/Stable
|
|
14
|
+
Classifier: Intended Audience :: Developers
|
|
15
|
+
Classifier: Operating System :: OS Independent
|
|
16
|
+
Classifier: Programming Language :: Python :: 3
|
|
17
|
+
Classifier: Programming Language :: Python :: 3 :: Only
|
|
18
|
+
Classifier: Topic :: Software Development :: Libraries
|
|
19
|
+
Classifier: Typing :: Typed
|
|
20
|
+
Requires-Python: >=3.9
|
|
21
|
+
Description-Content-Type: text/markdown
|
|
22
|
+
|
|
23
|
+
# llm-prices
|
|
24
|
+
|
|
25
|
+
Dated, source-cited LLM API prices for Python: the same table as the Rust crate
|
|
26
|
+
[`llm-prices`](https://crates.io/crates/llm-prices), generated from
|
|
27
|
+
[`prices.json`](https://github.com/Mattbusel/llm-prices/blob/main/prices.json). Pure Python, no
|
|
28
|
+
dependencies, no network access. Prices are USD per 1M tokens, and every row carries the
|
|
29
|
+
provider's pricing page and the date it was checked.
|
|
30
|
+
|
|
31
|
+
```python
|
|
32
|
+
import llm_prices
|
|
33
|
+
from llm_prices import Usage
|
|
34
|
+
|
|
35
|
+
p = llm_prices.lookup("claude-sonnet-4-6") # also dated, Bedrock, Vertex, prefixed ids
|
|
36
|
+
groq = llm_prices.lookup_provider("groq", "openai/gpt-oss-120b")
|
|
37
|
+
|
|
38
|
+
usage = Usage(input=2_048, cache_read=45_000, cache_write_5m=3_500, output=1_024)
|
|
39
|
+
p.cost_usage(usage).total # 0.048129 (float)
|
|
40
|
+
p.cost_usage(usage, exact=True).total # Decimal('0.048129')
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
`cost_usage` prices prompt-cache reads, cache writes by lifetime, batch discounts and the
|
|
44
|
+
long-context switch. Source and docs: https://github.com/Mattbusel/llm-prices
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["hatchling>=1.27"]
|
|
3
|
+
build-backend = "hatchling.build"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "llm-prices"
|
|
7
|
+
version = "1.2.0"
|
|
8
|
+
description = "Dated, source-cited LLM API prices (Anthropic, OpenAI, Gemini, DeepSeek, Mistral, xAI, Groq, Together, Fireworks, Cohere) per 1M tokens, with provider-aware model-id lookup and exact decimal costs. Zero dependencies."
|
|
9
|
+
readme = { content-type = "text/markdown", text = """
|
|
10
|
+
# llm-prices
|
|
11
|
+
|
|
12
|
+
Dated, source-cited LLM API prices for Python: the same table as the Rust crate
|
|
13
|
+
[`llm-prices`](https://crates.io/crates/llm-prices), generated from
|
|
14
|
+
[`prices.json`](https://github.com/Mattbusel/llm-prices/blob/main/prices.json). Pure Python, no
|
|
15
|
+
dependencies, no network access. Prices are USD per 1M tokens, and every row carries the
|
|
16
|
+
provider's pricing page and the date it was checked.
|
|
17
|
+
|
|
18
|
+
```python
|
|
19
|
+
import llm_prices
|
|
20
|
+
from llm_prices import Usage
|
|
21
|
+
|
|
22
|
+
p = llm_prices.lookup("claude-sonnet-4-6") # also dated, Bedrock, Vertex, prefixed ids
|
|
23
|
+
groq = llm_prices.lookup_provider("groq", "openai/gpt-oss-120b")
|
|
24
|
+
|
|
25
|
+
usage = Usage(input=2_048, cache_read=45_000, cache_write_5m=3_500, output=1_024)
|
|
26
|
+
p.cost_usage(usage).total # 0.048129 (float)
|
|
27
|
+
p.cost_usage(usage, exact=True).total # Decimal('0.048129')
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
`cost_usage` prices prompt-cache reads, cache writes by lifetime, batch discounts and the
|
|
31
|
+
long-context switch. Source and docs: https://github.com/Mattbusel/llm-prices
|
|
32
|
+
""" }
|
|
33
|
+
requires-python = ">=3.9"
|
|
34
|
+
license = "MIT"
|
|
35
|
+
license-files = ["LICENSE"]
|
|
36
|
+
authors = [{ name = "Matthew Busel" }]
|
|
37
|
+
keywords = ["llm", "pricing", "anthropic", "openai", "gemini", "tokens", "cost"]
|
|
38
|
+
classifiers = [
|
|
39
|
+
"Development Status :: 5 - Production/Stable",
|
|
40
|
+
"Intended Audience :: Developers",
|
|
41
|
+
"Operating System :: OS Independent",
|
|
42
|
+
"Programming Language :: Python :: 3",
|
|
43
|
+
"Programming Language :: Python :: 3 :: Only",
|
|
44
|
+
"Topic :: Software Development :: Libraries",
|
|
45
|
+
"Typing :: Typed",
|
|
46
|
+
]
|
|
47
|
+
dependencies = []
|
|
48
|
+
|
|
49
|
+
[project.urls]
|
|
50
|
+
Homepage = "https://github.com/Mattbusel/llm-prices"
|
|
51
|
+
Source = "https://github.com/Mattbusel/llm-prices/tree/main/python"
|
|
52
|
+
Changelog = "https://github.com/Mattbusel/llm-prices/blob/main/python/CHANGELOG.md"
|
|
53
|
+
Issues = "https://github.com/Mattbusel/llm-prices/issues"
|
|
54
|
+
|
|
55
|
+
[tool.hatch.build.targets.wheel]
|
|
56
|
+
packages = ["src/llm_prices"]
|
|
57
|
+
|
|
58
|
+
[tool.hatch.build.targets.sdist]
|
|
59
|
+
include = ["src/llm_prices", "tests", "CHANGELOG.md", "LICENSE", "pyproject.toml"]
|
|
60
|
+
|
|
61
|
+
[tool.pytest.ini_options]
|
|
62
|
+
pythonpath = ["src"]
|
|
63
|
+
testpaths = ["tests", "src"]
|
|
64
|
+
addopts = "--doctest-modules"
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
"""Dated, source-cited LLM API prices, with no dependencies and no network access.
|
|
2
|
+
|
|
3
|
+
The same table as the Rust crate ``llm-prices``, generated from
|
|
4
|
+
`prices.json <https://github.com/Mattbusel/llm-prices/blob/main/prices.json>`_: Anthropic,
|
|
5
|
+
OpenAI, Google Gemini and DeepSeek (re-read from their pricing pages every day) plus Mistral,
|
|
6
|
+
xAI, Cohere, Groq, Together AI and Fireworks AI. Every row carries the provider's official
|
|
7
|
+
pricing page and the date the price was read from it. Prices are USD per 1M tokens.
|
|
8
|
+
|
|
9
|
+
>>> import llm_prices
|
|
10
|
+
>>> p = llm_prices.lookup("claude-sonnet-5-5")
|
|
11
|
+
>>> p.input, p.cache_read
|
|
12
|
+
(2.0, 0.1)
|
|
13
|
+
>>> llm_prices.lookup("gpt-4o-2024-08-06").model
|
|
14
|
+
'gpt-4o'
|
|
15
|
+
>>> llm_prices.lookup_provider("groq", "openai/gpt-oss-120b").provider
|
|
16
|
+
'groq'
|
|
17
|
+
|
|
18
|
+
Price a whole response, prompt-cache reads and writes, batch discounts and the
|
|
19
|
+
long-context switch included, in floats or in exact decimals:
|
|
20
|
+
|
|
21
|
+
>>> from llm_prices import Usage
|
|
22
|
+
>>> usage = Usage(input=2_048, cache_read=45_000, cache_write_5m=3_500, output=1_024)
|
|
23
|
+
>>> llm_prices.lookup("claude-sonnet-4-6").cost_usage(usage, exact=True).total
|
|
24
|
+
Decimal('0.048129')
|
|
25
|
+
"""
|
|
26
|
+
|
|
27
|
+
from ._core import (
|
|
28
|
+
GENERATED,
|
|
29
|
+
CostBreakdown,
|
|
30
|
+
DecimalCostBreakdown,
|
|
31
|
+
LongContext,
|
|
32
|
+
Price,
|
|
33
|
+
Provider,
|
|
34
|
+
RateName,
|
|
35
|
+
Usage,
|
|
36
|
+
all_prices,
|
|
37
|
+
lookup,
|
|
38
|
+
lookup_provider,
|
|
39
|
+
)
|
|
40
|
+
|
|
41
|
+
#: Same as :func:`all_prices`, named like the Rust crate's ``llm_prices::all``. Not exported
|
|
42
|
+
#: by ``from llm_prices import *``, where it would hide the builtin ``all``.
|
|
43
|
+
all = all_prices
|
|
44
|
+
|
|
45
|
+
__version__ = "1.2.0"
|
|
46
|
+
|
|
47
|
+
__all__ = [
|
|
48
|
+
"GENERATED",
|
|
49
|
+
"CostBreakdown",
|
|
50
|
+
"DecimalCostBreakdown",
|
|
51
|
+
"LongContext",
|
|
52
|
+
"Price",
|
|
53
|
+
"Provider",
|
|
54
|
+
"RateName",
|
|
55
|
+
"Usage",
|
|
56
|
+
"all_prices",
|
|
57
|
+
"lookup",
|
|
58
|
+
"lookup_provider",
|
|
59
|
+
]
|