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.
pip install scrapmetalfromscrapmetalimportScrapMetalClientclient=ScrapMetalClient("your-api-key")
# Get current prices for all metalsprices=client.get_prices()
forpriceinprices:
print(f"{price['metal']}: ${price['price']}")
# Get prices for a specific metalcopper=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:
fromscrapmetalimportScrapMetalClientclient=ScrapMetalClient.signup("you@example.com")
# That's it — client is authenticated and ready to gostatus=client.get_status()
# No authentication requiredmetals=client.get_metals()
formetalinmetals:
print(f"{metal['name']}: {metal['grades']}")# All metalsprices=client.get_prices()
# Specific metalsteel=client.get_prices("steel")
copper=client.get_prices("copper")
aluminum=client.get_prices("aluminum")# Last 30 days of steel priceshistory=client.get_historical(metal="steel", days=30)
# Date range with grade filterhistory=client.get_historical(
metal="steel",
grade="HMS 1/2",
start="2024-01-01",
end="2024-06-30",
)
# Limit resultshistory=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.
usage=client.get_usage()
print(f"Requests: {usage['requests_used']}/{usage['requests_limit']}")
# Usage for the last 7 daysusage=client.get_usage(days=7)The SDK raises specific exceptions for different error types, making it easy to handle failures gracefully:
fromscrapmetalimportScrapMetalClient, AuthError, RateLimitError, NotFoundError, APIErrorclient=ScrapMetalClient("your-api-key")
try:
prices=client.get_prices("copper")
exceptAuthError:
print("Invalid API key. Check your credentials at scrapmetalapi.com.")
exceptRateLimitError:
print("Rate limit hit. Back off and retry, or upgrade your plan.")
exceptNotFoundError:
print("Metal not found. Use client.get_metals() to see available options.")
exceptAPIErrorase:
print(f"Unexpected error: {e.message} (HTTP {e.status_code})")| 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.
The client supports use as a context manager to automatically close the underlying HTTP session:
withScrapMetalClient("your-api-key") asclient:
prices=client.get_prices()
metals=client.get_metals()
# Session is closed automaticallyclient=ScrapMetalClient(
api_key="your-api-key",
base_url="https://scrapmetal-api.onrender.com", # defaulttimeout=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 |
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
| 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
MIT License. See LICENSE for details.