Getting Started with the Zscaler Python SDK
This guide applies to zscaler-oneapi-sdk-python. For information about zscaler-sdk-python, refer to the GitHub repository.
The Zscaler Python SDK simplifies automation of common administrative tasks by providing Python APIs for Zscaler products. It offers a unified, language-native OneAPI interface that uses a single authenticated session across product APIs, with built-in support for pagination, retries, error handling, and structured logging. The SDK supports Authentication Service, Cloud & Branch Connector (ZTW), Client Connector (ZCC), Zscaler Digital Experience (ZDX), Zscaler Internet Access (ZIA), and Zscaler Private Access (ZPA).
Prerequisites
Before you begin using the Python SDK, ensure that you have:
- Python 3.10 or later
pip(bundled with Python)- An Authentication Service-managed tenant with admin access to the products you plan to manage
- An API client created in Authentication Service. To learn more, see Getting Started with OneAPI and Adding an API Client.
Installation
Install zscaler-oneapi-sdk-python from PyPI in your virtual environment using one of the following options:
Option 1: pip (simplest)
python -m venv .venv
source .venv/bin/activate # Windows: .venv\Scripts\activate
pip install zscaler-oneapi-sdk-python==1.0.0
Option 2: uv (fastest)
uv is a modern, high-performance replacement for pip and venv.
# Install uv (one-time)
brew install pipx && pipx install uv # macOS
# or: pip install --user pipx && pipx install uv # Windows / Linux
# Create venv and install the SDK
cd <folder_of_your_choice>
uv venv
source .venv/bin/activate # Windows: .venv\Scripts\activate
uv pip install zscaler-oneapi-sdk-python==1.0.0
Verify the Installation
python -c "import zssdk; print('Zscaler SDK version:', zssdk.__version__)"
Authentication Requirements
The SDK authenticates via Authentication Service. Create an API client in Authentication Service and note the following values:
- Client ID: Public identifier for your API client.
- Client Secret: Confidential secret (for production, use JWT bearer with a private key instead of static secrets).
- Vanity Domain: Your organization's Authentication Service subdomain (for example,
acmeif your login URL ishttps://acme.zslogin.net).
Configure Credentials
Choose one of the following three options to configure your credentials. The SDK resolves them in the following order: constructor args → env vars → ~/.zscaler/config.
Option 1: Environment Variables (recommended)
# macOS / Linux
export ZSCALER_VANITY_DOMAIN="acme"
export ZSCALER_CLIENT_ID="your_client_id"
export ZSCALER_CLIENT_SECRET="your_client_secret"
REM Windows Command Prompt
set ZSCALER_VANITY_DOMAIN=acme
set ZSCALER_CLIENT_ID=your_client_id
set ZSCALER_CLIENT_SECRET=your_client_secret
# Windows PowerShell
$env:ZSCALER_VANITY_DOMAIN="acme"
$env:ZSCALER_CLIENT_ID="your_client_id"
$env:ZSCALER_CLIENT_SECRET="your_client_secret"
Option 2: Configuration File
# ~/.zscaler/config
[default]
vanity_domain = acme
client_id = your_client_id
client_secret = your_client_secret
from zssdk import Session
session = Session(profile_name="default")
Option 3: Constructor
from zssdk import Session
session = Session(
vanity_domain="acme",
client_id="your_client_id",
client_secret="your_client_secret",
)
Make an API Call
-
Save the following Python code as
test_connection.py.import zssdksession = zssdk.Session() # picks up ZSCALER_* env varszid = session.zidfor api_client in zid.api_clients.all().limit(5):print(api_client.id, api_client.name) -
Run the
test_connection.pyscript from within your virtual environment.source .venv/bin/activate # Windows: .venv\Scripts\activatepython test_connection.py
You should see a list of up to 5 API clients from your Authentication Service tenant. If you don't, turn on logging as described in the following section and review the log file.
Logging
Enable logging while you explore the SDK using the following code snippet.
import zssdk
from zssdk.zscore.config import Config, LoggerConfig
config = Config(
logger_config=LoggerConfig(
enabled=True,
verbose=True,
log_to_file=True,
log_file_path="zssdk.log",
)
)
session = zssdk.Session(config=config)
Fields containing sensitive information, such as authorization, client secret, and private keys, are auto-redacted. To learn more about full-format logging and redaction, see the Logging guide for complete reference.
Additional References
Use the following links to access SDK references for specific products:
Use the following links to access platform guides that include key concepts and procedural information:
- Authentication: OAuth 2.0, JWT bearer, and custom token providers
- Configuration: Configuration file, profiles, environment variables, and precedence
- Rate Limiting: Automatic retry behavior
- Error Handling: Unified exception hierarchy
- Pagination: Paginated vs. simple collections
- Session Management: Session lifecycle
- Logging: Formats, redaction, and tracing
Next Steps
- Read the Authentication guide and plan to use JWT bearer authentication rather than static client secrets in production.
- Explore the product help pages in the preceding section and implement your first resource using the CRUDL pattern.
- For production, configure logging with
logging_format="json"for structured logs.
Troubleshooting
The following sections provide troubleshooting steps for common issues you might encounter when working with the SDKs.
Authentication Failure
- Verify that your
client_idandclient_secretare correct and that the API client is active in Authentication Service. - Confirm that
vanity_domainmatches your Authentication Service tenant (subdomain only, not the full URL). - If you're testing against the Authentication Service beta environment, pass
cloud="beta"toSession(). Omitcloudfor production. - Ensure that the API client has the required scopes for the product to which you are making API calls.
SSL Certificate Error
- Update certificates using the following command:
pip install --upgrade certifi. - If you're using a corporate proxy, configure
Proxyin Config.
Rate Limit Exceeded
- The SDK retries
429responses automatically with exponential backoff and honorsRetry-After. If you're still hitting the limit, either slow the caller or catchThrottledExceptionfor application-specific handling. See the Rate Limiting guide.
Getting Help
Zscaler offers the following support channels to help you troubleshoot issues, engage with the community and experts, and request enhancements:
- Zscaler Community for questions and discussions
- Zscaler Support for account-specific issues
- GitHub issues in the SDK repository for bug reports and feature requests
Ready to build? Go to the Authentication guide to finalize your credentials, then choose a product reference from the preceding sections.