Skip to content

benswork-space/scrapmetal-python

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

ScrapMetal Python SDK

PyPI version License: MIT Python 3.8+

The official Python client for the ScrapMetal API — real-time and historical scrap metal pricing data for steel, copper, aluminum, and more.

Stop guessing on scrap metal prices. The ScrapMetal API aggregates pricing data from FRED, CME Group, LME, and SteelBenchmarker into a single, clean REST API. Build dashboards, automate purchasing decisions, and track market trends with just a few lines of Python.

Installation

pip install scrapmetal

Quick Start

from scrapmetal import ScrapMetalClient

client = ScrapMetalClient("your-api-key")

# Get current prices for all metals
prices = client.get_prices()
for price in prices:
    print(f"{price['metal']}: ${price['price']}")

# Get prices for a specific metal
copper = client.get_prices("copper")
print(f"Copper: ${copper['price']}/lb")

Don't have an API key yet? Sign up free at scrapmetalapi.com or create an account directly from Python:

from scrapmetal import ScrapMetalClient

client = ScrapMetalClient.signup("you@example.com")
# That's it — client is authenticated and ready to go

API Methods

Check API Status

status = client.get_status()
# No authentication required

List Available Metals

metals = client.get_metals()
for metal in metals:
    print(f"{metal['name']}: {metal['grades']}")

Get Current Prices

# All metals
prices = client.get_prices()

# Specific metal
steel = client.get_prices("steel")
copper = client.get_prices("copper")
aluminum = client.get_prices("aluminum")

Get Historical Prices (Pro Tier)

# Last 30 days of steel prices
history = client.get_historical(metal="steel", days=30)

# Date range with grade filter
history = client.get_historical(
    metal="steel",
    grade="HMS 1/2",
    start="2024-01-01",
    end="2024-06-30",
)

# Limit results
history = client.get_historical(metal="copper", days=90, limit=100)

The days parameter is a convenient shorthand. You can also pass start and end as ISO date strings or datetime objects.

Check Usage

usage = client.get_usage()
print(f"Requests: {usage['requests_used']}/{usage['requests_limit']}")

# Usage for the last 7 days
usage = client.get_usage(days=7)

Error Handling

The SDK raises specific exceptions for different error types, making it easy to handle failures gracefully:

from scrapmetal import ScrapMetalClient, AuthError, RateLimitError, NotFoundError, APIError

client = ScrapMetalClient("your-api-key")

try:
    prices = client.get_prices("copper")
except AuthError:
    print("Invalid API key. Check your credentials at scrapmetalapi.com.")
except RateLimitError:
    print("Rate limit hit. Back off and retry, or upgrade your plan.")
except NotFoundError:
    print("Metal not found. Use client.get_metals() to see available options.")
except APIError as e:
    print(f"Unexpected error: {e.message} (HTTP {e.status_code})")

Exception Hierarchy

Exception HTTP Code When
AuthError 401 Missing or invalid API key
ForbiddenError 403 Endpoint requires a higher-tier plan
NotFoundError 404 Metal or resource not found
RateLimitError 429 Too many requests
APIError 5xx / other Server errors or network issues

All exceptions inherit from ScrapMetalError, so you can catch everything with a single handler if preferred.

Context Manager

The client supports use as a context manager to automatically close the underlying HTTP session:

with ScrapMetalClient("your-api-key") as client:
    prices = client.get_prices()
    metals = client.get_metals()
# Session is closed automatically

Configuration

client = ScrapMetalClient(
    api_key="your-api-key",
    base_url="https://scrapmetal-api.onrender.com",  # default
    timeout=30,  # seconds, default
)
Parameter Type Default Description
api_key str required Your API key
base_url str https://scrapmetal-api.onrender.com API base URL
timeout int 30 Request timeout in seconds

Examples

See the examples/ directory for complete working examples:

  • quickstart.py — Get up and running in 30 seconds
  • price_alerts.py — Build a price alert system that notifies you when metals cross your thresholds

Pricing

Plan Price Requests Historical Data
Free $0/mo 100/day No
Pro $49/mo 10,000/day Yes
Enterprise Custom Unlimited Yes

View full pricing and sign up at scrapmetalapi.com

Links

License

MIT License. See LICENSE for details.

About

No description, website, or topics provided.

Resources

License

Stars

1 star

Watchers

0 watching

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages