Skip to main content
This guide will help you set up gRPC streaming with Python and connect to your first data stream in minutes.

Prerequisites

Before you begin, ensure you have:
  • API Credentials: Client ID from authentication setup
  • Python 3.7+: Python development environment
  • Network Access: Ability to connect to grpc-api.preprod.polymarketexchange.com:443

Step 1: Install Python gRPC Libraries

Required packages:
  • grpcio: gRPC runtime library
  • grpcio-tools: Tools for generating Python code from proto files
  • protobuf: Protocol buffer runtime
  • requests/httpx: For REST API authentication

Step 2: Obtain Protocol Buffer Definitions

Proto files define the gRPC service interfaces and message structures. The downloadable bundle is the canonical client contract: Download the proto files directly: polymarket-protos.zip
Do not make client startup depend on gRPC reflection. Reflection availability can differ by environment.

Step 3: Generate Python Client Code

Once you have the proto files, generate Python client code:
This generates:
  • *_pb2.py files: Message definitions
  • *_pb2_grpc.py files: Service stubs

Step 4: Authenticate

CRITICAL: Tokens must be refreshed every 3 minutes.Access tokens have a short expiration. Your application MUST implement automatic token refresh before expiration to maintain uninterrupted streaming connections.

Auth Domains

Obtain a JWT token using Private Key JWT authentication:
The response contains your access_token:
The expires_in is 180 seconds (3 minutes). Implement automatic token refresh before expiration.
See the Authentication Setup Guide for complete authentication details.

Step 5: Connect to Market Data Stream

Create your first streaming connection:
Price Representation: All prices are int64 values. Divide by the instrument’s price_scale to get the decimal price.price_scale varies by instrument. Get it from:
  • Instrument metadata via list_instruments or get_instrument_metadata
  • The price_scale field in order responses

Common Setup Issues

Connection Refused

  • Cause: Firewall blocking outbound gRPC connections
  • Solution: Ensure port 443 is open for outbound connections

Authentication Failed

  • Cause: Invalid or expired access token
  • Solution: Verify JWT, refresh token if expired (tokens expire every 3 minutes)

Import Errors

  • Cause: Generated proto files not in Python path
  • Solution: Ensure proto files are generated in the correct directory, or add to PYTHONPATH:

Module Not Found: polymarket

  • Cause: Proto files not generated or in wrong location
  • Solution: Re-run the protoc command from step 3, ensure you’re in the correct directory

Next Steps

Authentication Guide

Deep dive into authentication and token management

Market Data Streaming

Learn about all market data streaming features

Order Streaming

Subscribe to order execution updates

Need Help?

If you encounter issues during setup:
  1. Check the Error Handling Guide
  2. Review the Market Data Stream or Order Stream pages for complete implementations
  3. Contact onboarding@polymarket.us for assistance