Polygon.io Official Python Client (Deprecated)
The official Python client for Polygon.io's REST and Websocket APIs. This package (`polygon-api-client`) reached its end of life at version `1.16.3` and is no longer maintained. For active development, new features, and bug fixes, users should migrate to the successor library, `massive-api-client`.
Warnings
- breaking This `polygon-api-client` package is deprecated and no longer receives updates. The official client has been rebranded and released as `massive-api-client` (version `2.x.x` and higher). All users are strongly advised to migrate to the new package (`massive-api-client`) to receive critical updates, new features, and bug fixes.
- breaking Upon migrating from `polygon-api-client` (v1.x) to `massive-api-client` (v2.x+), the default API base URL changes from `https://api.polygon.io` to `https://api.massive.com`. While `https://api.polygon.io` still functions, ensure your code explicitly sets `base_url='https://api.polygon.io'` if you must connect to the old endpoint, or adapt your systems to the new `api.massive.com` default.
- gotcha An API key is required for authentication with the Polygon.io API. The client will raise an error if an API key is not provided or is invalid.
Install
-
pip install polygon-api-client==1.16.3 -
pip install massive-api-client
Imports
- RESTClient
from polygon import RESTClient
- WebSocketClient
from polygon.websocket import WebSocketClient
Quickstart
import os
from polygon import RESTClient
# Your Polygon API key
API_KEY = os.environ.get("POLYGON_API_KEY", "YOUR_API_KEY_HERE")
def main():
if not API_KEY or API_KEY == "YOUR_API_KEY_HERE":
print("Please set the POLYGON_API_KEY environment variable or replace 'YOUR_API_KEY_HERE' in the code.")
return
try:
with RESTClient(API_KEY) as client:
# Example: Get ticker types (endpoint availability depends on your API plan)
resp = client.reference_ticker_types()
print(f"Ticker Types: {resp.results}")
except Exception as e:
print(f"An error occurred: {e}")
if __name__ == "__main__":
main()