DFlowClient

The main client class for interacting with DFlow APIs

DFlowClient

The DFlowClient is the main entry point for interacting with the DFlow API. It provides access to all API modules and manages HTTP connections.

Import

from dflow import DFlowClient

Constructor

client = DFlowClient(
    environment: Literal["development", "production"] = "development",
    api_key: str | None = None,
    metadata_base_url: str | None = None,
    trade_base_url: str | None = None,
    ws_url: str | None = None,
)

Parameters

ParameterTypeDefaultDescription
environment"development" | "production""development"Environment to use. Development requires no API key.
api_keystr | NoneNoneAPI key for authenticated endpoints (required for production)
metadata_base_urlstr | NoneNoneCustom metadata API URL (overrides environment)
trade_base_urlstr | NoneNoneCustom trade API URL (overrides environment)
ws_urlstr | NoneNoneCustom WebSocket URL (overrides environment)

Environment Options

EnvironmentAPI KeyEndpointsUse Case
"development"Not requireddev-*.dflow.netTesting with real capital against Kalshi
"production"Required*.dflow.netProduction deployments

API Modules

The client provides access to the following API modules:

PropertyTypeDescription
marketsMarketsAPIMarket data and discovery
eventsEventsAPIEvent information
orderbookOrderbookAPIOrderbook data
tradesTradesAPITrade history
live_dataLiveDataAPILive market data
seriesSeriesAPISeries information
tagsTagsAPITag management
sportsSportsAPISports-specific data
searchSearchAPISearch functionality
ordersOrdersAPIOrder management
swapSwapAPIToken swaps
intentIntentAPIIntent-based trading
prediction_marketPredictionMarketAPIPrediction market operations
tokensTokensAPIToken information
venuesVenuesAPIVenue data
wsDFlowWebSocketWebSocket client

Examples

Basic Usage (Development)

from dflow import DFlowClient
 
# Development environment (default) - no API key required
# Uses dev-*.dflow.net endpoints for testing with real capital
client = DFlowClient()
 
# Access markets
response = client.markets.get_markets(status="active")
for market in response.markets:
    print(f"{market.ticker}: YES={market.yes_ask}")

Production Environment

from dflow import DFlowClient
 
# Production requires an API key
client = DFlowClient(environment="production", api_key="your-api-key")

With API Key

# Set API key at initialization
client = DFlowClient(api_key="your-api-key")
 
# Or set it later
client = DFlowClient()
client.set_api_key("your-api-key")

Custom URLs

client = DFlowClient(
    metadata_base_url="https://custom-metadata.example.com",
    trade_base_url="https://custom-trade.example.com",
    ws_url="wss://custom-ws.example.com"
)

Context Manager

with DFlowClient() as client:
    response = client.markets.get_markets()
    # HTTP client is automatically closed when exiting the context

Methods

set_api_key

Set or update the API key for authenticated requests.

client.set_api_key(api_key: str) -> None

close

Close the HTTP client connections.

client.close() -> None

On this page