sodapy is a Python client for the Socrata Open Data API (SODA), enabling programmatic access to datasets from Socrata-powered platforms. While the library is functional, it has been unmaintained since August 31, 2022, with no new features or bug fixes planned. The current version is 2.2.0, and it is compatible with Python 3.5-3.10.
pip install sodapyVerified import paths — ran on the pinned version, not inferred.
Initializes a Socrata client, retrieves the first 5 records from a public dataset (e.g., NYC 311 Service Requests), and fetches its metadata. It demonstrates setting up the client with an optional application token and credentials, and performing a basic data retrieval. Environment variables are used for secure credential handling.
Be aware of the unmaintained status; evaluate if the existing functionality meets your long-term needs without requiring future updates or bug fixes. For data management operations (creating/transforming data), consider `socrata-py` which targets the Socrata Data Management API.
Always use an application token when initializing the `Socrata` client, especially for frequent or large queries. You can obtain one from the Socrata website after creating an account. Pass it as the `app_token` argument: `Socrata(domain, app_token='YOUR_APP_TOKEN')`.
Understand the distinction between the SODA API and the Data Management API. If your task involves complex data transformations or is related to the data management user interface, investigate the `socrata-py` SDK which is designed for the Data Management API.
Increase the timeout limit for the `Socrata` client by setting the `timeout` parameter during initialization or by updating the `client.timeout` attribute. Example: `client = Socrata(..., timeout=60)` or `client.timeout = 60`.
Use the `$limit` and `$offset` parameters in your `client.get()` calls to request subsequent pages of data. To retrieve all records, you might need to make multiple paginated requests or use the `client.get_all()` method if available and suitable for your dataset.
pip install sodapy
from sodapy import Socrata
client = Socrata("data.cityofnewyork.us", app_token="YOUR_APP_TOKEN")from sodapy import Socrata
client = Socrata("data.cityofnewyork.us")
results = client.get("6wic-ph62") # Example: ensure it's in the format xxxx-xxxxfrom sodapy import Socrata
client = Socrata("data.cityofnewyork.us")
data = client.get("dataset_id")
if data:
print(data[0])
else:
print("No data found for this query.")