Python Quickstart
Call the Carapis API from Python with the requests library — set the Bearer header, hit GET /v2/listings, and read structured car data straight from JSON. No SDK required.
Install
pip install requestsSet your key
Store your key in an environment variable (get one at my.carapis.com ):
export CARAPIS_API_KEY="your_api_key_here"First request
import os
import requests
API_KEY = os.environ["CARAPIS_API_KEY"]
resp = requests.get(
"https://api.carapis.com/v2/listings",
params={"source": "encar", "limit": 20},
headers={"Authorization": f"Bearer {API_KEY}"},
)
resp.raise_for_status()
data = resp.json()
print(data["count"], "total matches")
for car in data["results"]:
print(car["make"], car["model"], car["year"], car["price"], car["currency"])Set source to any slug from the platforms page.
Filtering
resp = requests.get(
"https://api.carapis.com/v2/listings",
params={
"source": "encar",
"make": "Hyundai",
"model": "Grandeur",
"year_min": 2021,
"price_max": 30000000,
"limit": 20,
},
headers={"Authorization": f"Bearer {API_KEY}"},
)See every parameter in the listings reference.
Paging through all results
def all_listings(source, limit=20):
page = 1
while True:
resp = requests.get(
"https://api.carapis.com/v2/listings",
params={"source": source, "limit": limit, "page": page},
headers={"Authorization": f"Bearer {API_KEY}"},
)
results = resp.json()["results"]
if not results:
break
yield from results
page += 1
for car in all_listings("encar"):
print(car["id"], car["price"])Handling errors
resp = requests.get(url, params=params, headers=headers)
if not resp.ok:
err = resp.json().get("error", {})
print(resp.status_code, err.get("code"), err.get("message"))See Authentication, Pagination, Rate limits and Errors for the full reference.
Last updated on