↓ Skip to main content
All methods

stakepd.kalshi_data.KalshiClient.from_env

Class method API key
Signature
kd.KalshiClient.from_env(**kwargs)

Create an authenticated client from environment variables.

Reads KALSHI_API_KEY_ID, plus either KALSHI_PRIVATE_KEY_PATH (path to the .pem file) or KALSHI_PRIVATE_KEY (the PEM text itself). This is the recommended way to authenticate, because it keeps keys out of your code.

Parameters

**kwargs
Passed to the KalshiClient constructor, e.g. environment="demo" or timeout=60.

Returns

KalshiClient
An authenticated client.

Raises

KalshiAuthError
If the environment variables are not set.

See also

KalshiClient
Create a client for the Kalshi Trade API v2.
KalshiClient.get_positions
List your positions, one row per market.
KalshiClient.get_balance
Get your account balance.

Examples
#

Set the variables in ~/.zshrc (or your shell’s profile):

export KALSHI_API_KEY_ID="a1b2c3d4-..."
export KALSHI_PRIVATE_KEY_PATH="$HOME/.kalshi/kalshi_private_key.pem"

Then, in Python:

client = kd.KalshiClient.from_env()
print(client.is_authenticated)
Output:
True

Demo exchange (fake money, separate keys):

demo = kd.KalshiClient.from_env(environment="demo")

This method is also covered, alongside the rest of the module, in the overview guide.