Skip to content

Latest commit

History

1 Commit

Folders and files

NameName
Last commit message
Last commit date

Repository files navigation

ScrapMetal Python SDK

PyPI versionLicense: MITPython 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

fromscrapmetalimportScrapMetalClientclient=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 go

API Methods

Check API Status

status=client.get_status()
# No authentication required

List Available Metals

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

Get Current Prices

# All metalsprices=client.get_prices()
# Specific metalsteel=client.get_prices("steel")
copper=client.get_prices("copper")
aluminum=client.get_prices("aluminum")

Get Historical Prices (Pro Tier)

# 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.

Check Usage

usage=client.get_usage()
print(f"Requests: {usage['requests_used']}/{usage['requests_limit']}")
# Usage for the last 7 daysusage=client.get_usage(days=7)

Error Handling

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 Hierarchy

ExceptionHTTP CodeWhen
AuthError401Missing or invalid API key
ForbiddenError403Endpoint requires a higher-tier plan
NotFoundError404Metal or resource not found
RateLimitError429Too many requests
APIError5xx / otherServer 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:

withScrapMetalClient("your-api-key") asclient:
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", # defaulttimeout=30, # seconds, default
)
ParameterTypeDefaultDescription
api_keystrrequiredYour API key
base_urlstrhttps://scrapmetal-api.onrender.comAPI base URL
timeoutint30Request 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

PlanPriceRequestsHistorical Data
Free$0/mo100/dayNo
Pro$49/mo10,000/dayYes
EnterpriseCustomUnlimitedYes

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

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Used by

Contributors

Languages