Skip to main content

The official Netskope Python SDK — a modern, typed, and intuitive interface to the Netskope REST API v2.

Project description

Netskope Python SDK

The official Netskope Python SDK — a modern, typed, and intuitive interface to the Netskope REST API v2.

PyPI Python License

Why This SDK?

  • Hierarchical namespacesclient.alerts.list(), client.scim.users.create() — explore the entire API through autocomplete
  • Automatic pagination — just iterate, no page loops needed
  • Full type safety — Pydantic v2 models with complete type annotations
  • Sync + Async — choose the right client for your use case
  • Automatic retries — exponential backoff with jitter for transient errors
  • Rich exceptions — specific error types with request IDs for support escalation
  • Minimal dependencies — only httpx + pydantic
  • Python 3.11+ — modern Python, no legacy baggage

Installation

pip install netskope-py-sdk

Quick Start

from netskope import NetskopeClient

# Create a client (or set NETSKOPE_TENANT and NETSKOPE_API_TOKEN env vars)
client = NetskopeClient(
    tenant="mycompany.goskope.com",
    api_token="your-v2-api-token",
)

# List high-severity alerts — pagination is automatic
for alert in client.alerts.list(query='severity eq "high"'):
    print(f"{alert.alert_name}{alert.user}{alert.severity}")

# Query network events
for event in client.events.list("network", query='user eq "alice@example.com"'):
    print(f"{event.src_ip}{event.dst_ip}")

# Manage URL allow/block lists
blocklist = client.url_lists.create("threat-iocs", ["malware.example.com"])
client.url_lists.deploy()  # deploy pending changes

# List publishers
for pub in client.publishers.list():
    print(f"{pub.publisher_name}{pub.status}")

# SCIM user provisioning
for user in client.scim.users.list():
    print(f"{user.user_name} active={user.active}")

Async Usage

from netskope import AsyncNetskopeClient

async with AsyncNetskopeClient(tenant="...", api_token="...") as client:
    async for alert in client.alerts.list():
        print(alert.alert_name)

Configuration

Environment Variables

Variable Description
NETSKOPE_TENANT Tenant hostname (e.g. mycompany.goskope.com)
NETSKOPE_API_TOKEN REST API v2 token

Client Options

client = NetskopeClient(
    tenant="mycompany.goskope.com",
    api_token="...",
    timeout=60.0,           # request timeout (seconds)
    max_retries=5,          # retry count for transient errors
    backoff_factor=1.0,     # exponential backoff base
)

Multiple Tenants

prod = NetskopeClient(tenant="prod.goskope.com", api_token=prod_token)
staging = NetskopeClient(tenant="staging.goskope.com", api_token=staging_token)

API Reference

Alerts

# List with JQL filtering
alerts = client.alerts.list(query='alert_type eq "DLP"')
for alert in alerts:
    print(alert.alert_name, alert.severity, alert.user)

# Get a single alert
alert = client.alerts.get("alert-id-123")

# Page-level access
for page in client.alerts.list().pages():
    print(f"Page: {len(page.items)} items, {page.total} total")

# Collect all at once (with safety limit)
all_alerts = client.alerts.list().to_list(max_items=5000)

Events

from datetime import datetime

# Query by event type
for event in client.events.list("application"):
    print(event.user, event.app, event.activity)

# Network events with time range
for event in client.events.list(
    "network",
    start_time=datetime(2026, 1, 1),
    end_time=datetime(2026, 3, 1),
):
    print(event.src_ip, event.dst_ip)

# Supported types: alert, application, network, page, incident,
#   audit, infrastructure, clientstatus, epdlp, transaction

URL Lists

# CRUD operations
url_list = client.url_lists.create("blocklist", ["bad.com", "evil.org"])
url_list = client.url_lists.update(url_list.id, urls=["bad.com", "evil.org", "new.bad.com"])
client.url_lists.delete(url_list.id)

# Deploy all pending changes
client.url_lists.deploy()

Publishers

# List all publishers
for pub in client.publishers.list():
    print(f"{pub.publisher_name}: {pub.status} ({pub.apps_count} apps)")

# Create a publisher
new_pub = client.publishers.create(name="aws-us-east-1")

# Get by ID
pub = client.publishers.get(publisher_id=42)

Private Apps (ZTNA)

# List private apps
for app in client.private_apps.list():
    print(f"{app.app_name}{app.host}:{app.port}")

# Create a private app
app = client.private_apps.create(
    name="internal-dashboard",
    host="10.0.0.5",
    port="443",
    protocols=["TCP"],
    publisher_ids=[1, 2],
)

SCIM (Users & Groups)

# Users
for user in client.scim.users.list():
    print(user.user_name, user.active)

user = client.scim.users.create(
    user_name="alice@example.com",
    email="alice@example.com",
    display_name="Alice Smith",
)

# Groups
for group in client.scim.groups.list():
    print(f"{group.display_name}: {len(group.members)} members")

Incidents

# List incidents
for incident in client.incidents.list(query='severity eq "critical"'):
    print(incident.incident_id, incident.severity, incident.status)

# Get user risk score
uci = client.incidents.get_uci("user@example.com")
print(f"Risk score: {uci.score}")

# Get UBA anomalies
anomalies = client.incidents.get_anomalies(["user@example.com"])

Steering & Infrastructure

# Get steering config
config = client.steering.get_config("npa")

# List PoPs
for pop in client.steering.list_pops():
    print(f"{pop.name}{pop.region}")

# List IPSec tunnels
for tunnel in client.steering.list_tunnels():
    print(f"{tunnel.name}: {tunnel.status}")

Error Handling

from netskope import (
    NetskopeError,
    AuthenticationError,
    NotFoundError,
    RateLimitError,
    ForbiddenError,
)

try:
    alert = client.alerts.get("nonexistent")
except NotFoundError as e:
    print(f"Not found: {e.message}")
    print(f"Request ID: {e.request_id}")  # for support escalation
except RateLimitError as e:
    print(f"Rate limited — retry after {e.retry_after}s")
except AuthenticationError:
    print("Invalid or expired API token")
except ForbiddenError:
    print("Token lacks required scope")
except NetskopeError as e:
    print(f"SDK error: {e}")

Context Managers

# Sync
with NetskopeClient(tenant="...", api_token="...") as client:
    alerts = client.alerts.list().to_list()

# Async
async with AsyncNetskopeClient(tenant="...", api_token="...") as client:
    alerts = await client.alerts.list().to_list()

Logging

import logging

# See all requests at INFO level
logging.getLogger("netskope").setLevel(logging.INFO)

# Full request/response debug (tokens redacted)
logging.getLogger("netskope").setLevel(logging.DEBUG)

Requirements

  • Python 3.11+
  • httpx >= 0.27
  • pydantic >= 2.0

License

MIT

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

netskope_py_sdk-1.0.1.tar.gz (58.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

netskope_py_sdk-1.0.1-py3-none-any.whl (39.5 kB view details)

Uploaded Python 3

File details

Details for the file netskope_py_sdk-1.0.1.tar.gz.

File metadata

  • Download URL: netskope_py_sdk-1.0.1.tar.gz
  • Upload date:
  • Size: 58.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.2.1 CPython/3.14.0 Darwin/25.3.0

File hashes

Hashes for netskope_py_sdk-1.0.1.tar.gz
Algorithm Hash digest
SHA256 0f1035b797118de5435c177f4de781010f762375ae34b472222c97044c59d204
MD5 216b7f6fc6ed7077e7f750f26c235aea
BLAKE2b-256 0dabba8b8164f39e0014cedd1cd269ac1cc6f860d5c0deee84d01a8811f54a6f

See more details on using hashes here.

File details

Details for the file netskope_py_sdk-1.0.1-py3-none-any.whl.

File metadata

  • Download URL: netskope_py_sdk-1.0.1-py3-none-any.whl
  • Upload date:
  • Size: 39.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.2.1 CPython/3.14.0 Darwin/25.3.0

File hashes

Hashes for netskope_py_sdk-1.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 faa42e0c5d753248988cb1b1dba3666a6d9ef78fcbdd1618c6590398e9001e07
MD5 1d66921052b035d2c31ae038cd1ab0c0
BLAKE2b-256 d9241ecc10a9dae6151c3a3b078584c13b2979d44130bb0ff5c92aa8b1830356

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page