API reference¶
Auto-generated from the SDK's Google-style docstrings via mkdocstrings.
Client¶
zotniq.Zotniq
¶
Zotniq SDK client for runtime DLP decisions.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
api_key
|
Optional[str]
|
Zotniq API key ( |
None
|
base_url
|
Optional[str]
|
Zotniq API base URL. Defaults to the public endpoint. Point at a self-hosted deployment for air-gapped scenarios. |
None
|
timeout
|
Optional[float]
|
Per-request timeout in seconds. Default 30. |
None
|
max_retries
|
Optional[int]
|
Number of retries on 429/5xx before raising. Default 2. |
None
|
on_decision
|
Optional[Callable[..., Any]]
|
Optional callback fired after every
|
None
|
Example
client = Zotniq() result = client.preflight.check("hello", destination="AI_TOOL", mode="local") result.decision
Source code in zotniq/_client.py
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 | |
siem_stats()
¶
detect(text)
¶
Run local regex + validator detection. Zero network calls.
Convenience over client.preflight.check(..., mode="local") when
the caller only wants findings without a decision or masked_text.
Example::
client = Zotniq()
[f.type for f in client.detect("bob@x.com")] # -> ["EMAIL"]
Source code in zotniq/_client.py
mask(text)
¶
Return the format-preserving masked version of text.
Always local. See zotniq.detection.mask_text for the same
function without the client wrapper.
Example
Zotniq().mask("SSN 123-45-6789") 'SSN XXX-XX-6789'
Source code in zotniq/_client.py
with_options(timeout=None, max_retries=None)
¶
Return a new client with per-call overrides.
Matches the OpenAI SDK's with_options pattern. Cheap: reuses
config, creates a new transport. Original client unchanged.
long = client.with_options(timeout=120)
result = long.preflight.check(text=very_large_text, destination="AI_TOOL")
Source code in zotniq/_client.py
close()
¶
Release resources: SIEM queue flush + httpx connection pool.
Safe to call multiple times. Prefer the context manager form
(with Zotniq(...) as client:) for automatic cleanup.
Source code in zotniq/_client.py
zotniq.AsyncZotniq
¶
Async twin of Zotniq. See Zotniq for full argument docs.
Source code in zotniq/_async_client.py
detect(text)
¶
Local regex detection — synchronous, no network. Same as Zotniq.detect.
Source code in zotniq/_async_client.py
mask(text)
¶
aclose()
async
¶
Async cleanup: flush SIEM queue + close httpx AsyncClient pool.
Preflight¶
zotniq.resources.preflight.PreflightResource
¶
Attached at client.preflight. Owns preflight decision calls.
Source code in zotniq/resources/preflight.py
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 | |
check(text, destination, mode='auto', actor_id=None)
¶
Run a preflight check and return the decision.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
text
|
str
|
The candidate content. Never persisted server-side under
any retention_mode (Bug F invariant); only decision metadata
lands in |
required |
destination
|
DestinationLike
|
Where the content is going. Drives which policy
applies. Accepts |
required |
mode
|
Mode
|
See module docstring for resolution. |
'auto'
|
actor_id
|
Optional[str]
|
Who inside your app made this call. Populates the
|
None
|
Returns:
| Type | Description |
|---|---|
PreflightResult
|
A |
PreflightResult
|
(when decision is |
PreflightResult
|
for correlation with server-side audit rows. |
Raises:
| Type | Description |
|---|---|
AuthError
|
mode="cloud" without an api_key configured. |
NetworkError
|
cloud call failed and no fallback was requested. |
ValidationError
|
server rejected the request body (rare). |
Example
from zotniq import Zotniq client = Zotniq() result = client.preflight.check( ... "email me at bob@example.com", ... destination="AI_TOOL", ... mode="local", ... ) result.decision.value 'ALLOWED_WITH_MASKING'
Source code in zotniq/resources/preflight.py
zotniq.resources.preflight.AsyncPreflightResource
¶
Async twin of PreflightResource. Same public API, awaitable calls.
Source code in zotniq/resources/preflight.py
check(text, destination, mode='auto', actor_id=None)
async
¶
Async twin of PreflightResource.check. Same semantics + actor_id.
Source code in zotniq/resources/preflight.py
Types¶
zotniq.types.Decision
¶
Bases: str, Enum
Policy decision returned by client.preflight.check().
ALLOWED: no sensitive data detected, safe to send.ALLOWED_WITH_MASKING: sensitive data found and masked; sendresult.masked_textinstead of the original.BLOCKED: policy forbids sending this content to this destination.
Source code in zotniq/types.py
zotniq.types.Destination
¶
zotniq.types.Finding
¶
Bases: BaseModel
One aggregated detection finding attached to a PreflightResult.
Superset of the four write-path shapes (post-Bug H server unification):
type is always populated; location/action/confidence are
present when the underlying detector supplied them.
Source code in zotniq/types.py
zotniq.types.PreflightResult
¶
Bases: BaseModel
Full decision + findings returned by client.preflight.check().
masked_text is populated only when decision == ALLOWED_WITH_MASKING.
request_id is populated for cloud calls (echoed from the server's
x-request-id header) and set to a local UUID for local-mode calls,
so every decision is correlatable.
monitor_mode reflects observe-only enforcement. When True, decision
will be ALLOWED (never blocked or masked in the wire response) but the
server-side audit row captured the true decision that would have applied
under enforcement. Check this flag before assuming ALLOWED means the
payload was actually clean.
Source code in zotniq/types.py
Errors¶
zotniq.errors.ZotniqError
¶
zotniq.errors.AuthError
¶
Bases: ZotniqError
Missing / invalid API key, or 401/403 from the server.
zotniq.errors.RateLimitError
¶
Bases: ZotniqError
429 from the server. Retry-After honored automatically up to max_retries.
Source code in zotniq/errors.py
zotniq.errors.ValidationError
¶
Bases: ZotniqError
4xx malformed request. Usually a client-side bug in the calling code.
zotniq.errors.NetworkError
¶
Bases: ZotniqError
5xx / timeout / DNS failure during a cloud call.
Never falls back to local silently — the caller sees the failure and
decides. Set mode="cloud_with_fallback" per-call to opt into
automatic local fallback instead.
Source code in zotniq/errors.py
Detection primitives (zero-dep)¶
zotniq.detection.detect(content, include_samples=True)
¶
Main detection entry point.
zotniq.detection.mask_text(text, findings=None)
¶
Mask all sensitive data in text.
Detects and masks all sensitive data in the input text, replacing each occurrence with its masked equivalent.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
text
|
str
|
The text to mask |
required |
findings
|
Optional[list[Finding]]
|
Optional pre-computed findings (if None, will detect) |
None
|
Returns:
| Type | Description |
|---|---|
str
|
Text with all sensitive data masked |
Source code in zotniq/detection/masker.py
SIEM forwarders¶
zotniq.siem.WebhookForwarder
¶
Bases: BaseForwarder
POST each event as JSON to url.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
url
|
str
|
Full HTTPS endpoint. HTTP allowed but discouraged. |
required |
headers
|
Optional[dict]
|
Extra headers merged on every request. Use for bearer tokens, API keys, or SIEM-specific auth headers. |
None
|
timeout
|
float
|
Per-request timeout in seconds. Default 10. |
10.0
|
Example
forwarder = WebhookForwarder( url="https://soc.acme.com/hooks/dlp", headers={"Authorization": "Bearer secret-token"}, ) client = Zotniq(api_key="zot_sk_...", on_decision=forwarder)
Source code in zotniq/siem/webhook.py
zotniq.siem.SplunkForwarder
¶
Bases: BaseForwarder
POST to Splunk HEC.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
url
|
str
|
Full HEC endpoint including path, e.g.
|
required |
token
|
str
|
HEC token from Splunk's Data Inputs → HTTP Event Collector. |
required |
source
|
str
|
|
'zotniq-sdk'
|
sourcetype
|
str
|
|
'zotniq:decision'
|
index
|
Optional[str]
|
Optional Splunk index override. |
None
|
timeout
|
float
|
Per-request timeout. Default 10s. |
10.0
|
verify_ssl
|
bool
|
Set False for self-signed HEC. Default True. |
True
|
Example
forwarder = SplunkForwarder( url="https://splunk.acme.com:8088/services/collector", token="hec-token-here", index="dlp_events", ) client = Zotniq(api_key="zot_sk_...", on_decision=forwarder)
Source code in zotniq/siem/splunk.py
zotniq.siem.DatadogForwarder
¶
Bases: BaseForwarder
POST to Datadog Logs API.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
api_key
|
str
|
Datadog API key (not app key). |
required |
site
|
str
|
Datadog region. Default |
'datadoghq.com'
|
ddsource
|
str
|
Datadog |
'zotniq'
|
service
|
str
|
Datadog |
'dlp'
|
tags
|
Optional[list[str]]
|
Extra tags appended to every event. |
None
|
timeout
|
float
|
Per-request timeout. Default 10s. |
10.0
|
Example
forwarder = DatadogForwarder( api_key="dd-api-key", site="datadoghq.com", service="chat-backend", tags=["env:prod", "team:security"], ) client = Zotniq(api_key="zot_sk_...", on_decision=forwarder)
Source code in zotniq/siem/datadog.py
zotniq.siem.FileForwarder
¶
Bases: BaseForwarder
Append events as newline-delimited JSON to a local file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
Union[str, PathLike]
|
Destination file path. Parent directory must exist. |
required |
format
|
str
|
Only |
'ndjson'
|
Example
forwarder = FileForwarder(path="/var/log/zotniq/decisions.ndjson") client = Zotniq(api_key="zot_sk_...", on_decision=forwarder)
Concurrency: writes are serialized via a file-level lock so multiple Zotniq clients in the same process can share a target file without interleaving lines.
Source code in zotniq/siem/file.py
OpenAI integration¶
zotniq.integrations.openai.wrap_openai(zotniq_client, **openai_kwargs)
¶
Return an OpenAI-compatible client that runs preflight on user messages.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
zotniq_client
|
Zotniq
|
A |
required |
**openai_kwargs
|
Any
|
Passed through to the underlying |
{}
|
Raises:
| Type | Description |
|---|---|
ImportError
|
openai package not installed. Install with
|