Skip to main content

A simple Python SDK to scrape and retrieve pricing information for Large Language Models (LLMs) from an external webpage, with structured models for easy integration and usage.

Project description

LLM Price Scraper

LLM Price Scraper is a Python package designed to scrape and organize pricing information for large language models (LLMs) from the following sources:

Installation

You can install the package using pip:

pip install llm-price-scraper==1.0.3

Usage

Once you have installed the scrapper, you can use it to quickly retrieve the current pricing information from the website.

from llm_price_scraper.scrapers import LlmPricingScraper

# Get the pricing information
pricing_data = LlmPricingScraper.scrape()

# Loop through each pricing entry and print data
for entry in pricing_data:
    print(f"Model: {entry.model}")
    print(f"Provider: {entry.provider}")
    print(f"1M input tokens: {entry.input_tokens_price}$")
    print(f"1M output tokens: {entry.output_tokens_price}$")
    print(f"Context: {entry.context}")
    print(f"Source: {entry.source}")
    print(f"Updated: {entry.updated}")
    print("-" * 40)
    
# get all gpt-4o models
gpt_4o_models = [entry for entry in pricing_data if "gpt-4o" in entry.model.lower()]
print("GPT-4o models:")
for entry in gpt_4o_models:
    print(f"Model: {entry.model}")
    print(f"Provider: {entry.provider}")
    print(f"1M input tokens: {entry.input_tokens_price}$")
    print(f"1M output tokens: {entry.output_tokens_price}$")
    print(f"Context: {entry.context}")
    print(f"Source: {entry.source}")
    print(f"Updated: {entry.updated}")
    print("-" * 40)

You can also chose the source of the data you want to scrape by passing the source as an argument to the scrape method. The available sources are defined in the DataSources enum.

from llm_price_scraper.scrapers import LlmPricingScraper, DataSources

pricing_data = LlmPricingScraper.scrape(DataSources.HUGGINGFACE)

Example Output

After running the above code, you should see an output like this:

Model: gpt-4-32k
Provider: OpenAI
1M input tokens: 60
1M output tokens: 120
Context: 32K
Source: https://www.botgenuity.com/tools/llm-pricing
Updated: March 16, 2024
----------------------------------------
...

Error Handling

In case of a failure to connect to the webpage, an exception will be thrown with an appropriate message. For example:

Exception: Failed to retrieve the webpage. Status code: 404

Contributing

Contributions, bug reports, and feature requests are welcome! Feel free to submit a pull request or open an issue 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

llm_price_scraper-1.0.3.tar.gz (7.3 kB view details)

Uploaded Source

Built Distribution

llm_price_scraper-1.0.3-py3-none-any.whl (9.9 kB view details)

Uploaded Python 3

File details

Details for the file llm_price_scraper-1.0.3.tar.gz.

File metadata

  • Download URL: llm_price_scraper-1.0.3.tar.gz
  • Upload date:
  • Size: 7.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.11.9

File hashes

Hashes for llm_price_scraper-1.0.3.tar.gz
Algorithm Hash digest
SHA256 27476af125bda72badf121b2a6a687f9cded0ef0b05f7f473d9d7a4751814af3
MD5 57e357fef91cbd0890d5bb45b5df0878
BLAKE2b-256 c0b214de9ce8c594a2e4bdaafd77a7c1b5a662b0ab780e5fe6cef6bef211739b

See more details on using hashes here.

File details

Details for the file llm_price_scraper-1.0.3-py3-none-any.whl.

File metadata

File hashes

Hashes for llm_price_scraper-1.0.3-py3-none-any.whl
Algorithm Hash digest
SHA256 c12e524c029bbe8574782dee09ccf5eae3ade95cb87c023a32848f8bebbff3ea
MD5 2bc83468fd14e06bf5b2a5cf9906f603
BLAKE2b-256 75f0bec61c5a7eb4e3aafefbaf494a48d5cea5788be856f02e33a6079c9334a8

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page