Polygon.io Official Python Client (Deprecated)

1.16.3 · deprecated · verified Mon Apr 13

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

Install

Imports

Quickstart

Initialize the REST client and fetch basic reference data. Ensure your API key is set via environment variable or directly in the code. This version of the client defaults to the `api.polygon.io` endpoint.

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()

view raw JSON →