FAQ
This page is for the practitioner who has a quick question and wants the answer in one paragraph. Long-form explanations live in the guides; this page is the 30-second-answer index. Every entry links to the guide that covers the topic in depth.
Setup
Why does SVIClient(...) return immediately without verifying the URL?
By design. Construction is side-effect-free, so you can build a client in a unit test
or a notebook without making network calls. Use client.verify_connection() (or
await client.verify_connection_async()) when you want an explicit connectivity check.
See SVIClient and API Layers.
Where is the from_env() constructor reading variables from?
SVIClient.from_env() reads SASVI_BASE_URL, and for auth SASVI_ACCESS_TOKEN,
SASVI_CLIENT_ID + SASVI_CLIENT_SECRET, or SASVI_USERNAME + SASVI_PASSWORD. The two
SAS Logon grants also read SASVI_TOKEN_URL (to override the token endpoint) and
SASVI_SCOPES. The rest are SASVI_TIMEOUT, SASVI_VERIFY_SSL, SASVI_LOG_LEVEL,
SASVI_LOG_HTTP, SASVI_LOG_HTTP_LEVEL, SASVI_LOG_HTTP_RESPONSE_BODY and
SASVI_LOG_HTTP_BODY_LIMIT. Explicit constructor kwargs always override env vars.
It reads a .env file, a profile or the sasvi auth login cache only when you pass
env_file=, profile= or use_login_cache=True.
See Authentication.
Can I pass a raw httpx2 client?
Pass sync_httpx_args= and async_httpx_args= mappings. They are forwarded
verbatim to the underlying httpx2.Client(...) and httpx2.AsyncClient(...)
constructors. Use this to swap the default transport for a MockTransport in tests.
To size the connection pool, pass limits=httpx2.Limits(...) to SVIClient: it caps
the whole client, because every service shares one pool. See Testing
and Performance.
Is the SDK thread-safe?
A sync SVIClient is safe to share across threads. tests/test_concurrency.py pins
what that means:
- 32 threads calling
client.documents.geton one client each get their own document back. - 16 threads that find the token expired make one token request between them. After a 401, 8 simultaneous requests refetch the token at most twice.
- The request deadline and the
no_retry()scope belong to the calling thread. A plainthreading.Threadstarts without them.
An async client belongs to one event loop. Use one client per loop, and share it
freely between the tasks of that loop: the same guarantees hold for 32 tasks. Using
it from a second loop raises EventLoopChangedError.
A bound handle is not safe to share. A write that mutates it (for example
Document.refresh() replacing the snapshot in place) can interleave with another
thread's write on the same object. Use a fresh handle per thread or task, or
serialize mutations with a lock.
preview_next() and preview() are scoped to the caller. A preview in one thread
or task does not touch the requests of another, so a worker can keep writing while
a second thread previews. Three rules follow from how Python copies context:
- A task or an
asyncio.to_threadcall started inside the block shares the block's capture. Two requests from agatherinside one block raisesasvi.errors.PreviewMultiCallError. - A task started inside the block that sends after the block ended gets an
SVIError. Its request is not sent. Start such a task outside the block. - A nested
preview_next()shadows the outer one until it exits.
Every SDK client in the block is covered, including client.custom and the SAS Logon
token clients. Nothing is sent and no token is fetched.
Can I run the SDK in AWS Lambda?
Yes. import sasvi loads almost nothing; most of the cold start is building the first
client, which loads the generated service modules. Call SVIClient.from_env() lazily inside
the handler if cold start matters. Measure
the baseline for your own runtime with python -X importtime -c "import sasvi". The
retry policy's request_deadline_seconds is the right knob to bound the worst case
per invocation.
Authentication
Which auth provider should I pick?
| Scenario | Provider |
|---|---|
| Already have a bearer token | StaticTokenProvider |
| Service-to-service, CI, cron job | ClientCredentialsTokenProvider |
| Interactive notebook or desktop CLI | AuthorizationCodeTokenProvider (PKCE flow) |
| Dev/test only (NOT recommended for prod) | UsernamePasswordTokenProvider |
See Authentication for the deeper "why".
My token expires mid-job. How do I refresh?
The three acquiring providers (AuthorizationCodeTokenProvider,
ClientCredentialsTokenProvider and UsernamePasswordTokenProvider) refresh
transparently when BearerTokenAuth sees a 401: the SDK calls
provider.invalidate_rejected(token) with the token the server refused, and retries
the request once with a fresh token. The provider keeps its cache when another
caller has already replaced that token, so a burst of 401s costs one token request.
You don't have to do anything. A custom provider with only invalidate() still
works: the SDK calls that instead. StaticTokenProvider has neither method, so it
cannot refresh; the 401 is returned to you.
For long-running jobs use ClientCredentialsTokenProvider (no refresh token expiry)
rather than AuthorizationCodeTokenProvider (whose refresh token has a finite life).
How do I see what the token actually looks like?
print(repr(client.auth)) # safe; secrets are redacted in __repr__
client.auth.to_dict() # redacted JSON-shaped snapshot for diagnostics
Never log the result of client.auth.get_token(); that is the raw bearer token.
Documents and fields
How do I update a field whose value is a user reference?
VI stores user/group references as JSON-encoded arrays. Use UserRef / GroupRef:
from sasvi import UserRef, GroupRef
doc.update_fields(
assigned_user_id=UserRef(id="analyst.user"),
assigned_group_id=GroupRef(id="triage-team"),
)
The SDK serializes these to the wire format the API expects. See Documents guide.
Why doesn't assigning into Document.fields do anything?
It isn't read-only, but writing to it accomplishes nothing. document.fields builds
a fresh plain dict from the current snapshot on every access, so
doc.fields["status"] = "x" mutates a throwaway copy and the next read gives the old
value back. Use doc.update_fields(status="x") (or doc.update({...})) to persist a
change.
What's the difference between to_dict() and raw_dict() on a handle?
to_dict(). A curated, JSON-friendly snapshot of the object, safe for logging.raw_dict(). The underlying generated payload as plain Python (deep-copied), matching the VI wire format. Use it when you need to round-trip an object back into another SDK call.
Alerts
How do I handle dispositions that prompt for fields?
Catch DispositionPromptRequiredError and inspect exc.missing:
from sasvi import errors
try:
alert.disposition(disposition_id=did)
except errors.DispositionPromptRequiredError as exc:
alert.disposition(disposition_id=did, **collect(exc.missing))
exc.missing lists every keyword still needed at once. The
disposition-with-prompts recipe shows a
collect() that builds each one in the type disposition() takes.
Can I disposition many alerts in parallel?
Yes. Use the async siblings and bound your concurrency:
import asyncio
sem = asyncio.Semaphore(20)
async def one(alert_id):
async with sem:
alert = await client.alerts.get_async(alert_id=alert_id)
return await alert.disposition_async(
disposition_id=disposition_id,
resolution_code="PRODUCTIVE",
)
results = await asyncio.gather(*(one(aid) for aid in alert_ids))
See Async and Performance.
Search
Why is Search.count() returning 0 for what I know is a non-empty index?
Most likely causes, in order:
types(...)is too narrow. Pass the right entity type.- A
filter(...)excludes more than you think. Log the assembled SAND payload withlog_http_response_body=True. - You called
.count()before any.text(...)/.filter(...)and the SAND visualization has its own gating.
Use client.search.types("alerts").count() against a known broad type as a sanity
check.
Should I use Q.text(...) or Q.safe_text(...)?
Use Q.safe_text(...) for any value that isn't a constant in your source code.
Q.text is Lucene-by-default and a : or * in user input will change the
query meaning.
Search.text(...) is sugar for Search.query(Q.safe_text(...)), so it's safe
to call on any input. Use Search.query(Q.text(...)) only when you want raw
Lucene syntax (wildcards, field-scoped searches, boolean operators).
See Search DSL.
Why does coordinate order in geo helpers feel reversed?
VI / SAND uses (longitude, latitude), the same order GeoJSON uses. Most online
tools display (latitude, longitude). Double-check before you paste coordinates.
Async
How do I run an async pipeline that fans out 100 alert lookups?
import asyncio
sem = asyncio.Semaphore(20)
async def fetch(alert_id):
async with sem:
return await client.alerts.get_async(alert_id=alert_id)
alerts = await asyncio.gather(*(fetch(a) for a in alert_ids))
See Async deep dive.
Why do some async methods feel slower than I'd expect?
Almost every _async method awaits the HTTP client on the event loop. Two still use a worker
thread: UsernamePasswordTokenProvider.get_token_async and
AuthorizationCodeTokenProvider.get_token_async, whose token request runs inside a single-flight
lock, and the local file writes of AttachmentsManager.download_to_async. A
slow async call is more often waiting on the connection pool: all services of one client share
it, so raise limits= if many calls run at once. See Async deep dive and the
Performance guide.
Operations
How do I see what HTTP requests the SDK is actually making?
client = sasvi.SVIClient(
base_url=base_url,
auth=auth,
log_http=True,
log_http_level="INFO",
)
That logs one summary line per request (method, sanitized URL, status, duration, retry outcome). For full request/response bodies see Logging.
How do I bypass retries for a single call?
The retry policy is per-client. To opt one call out, swap clients:
no_retry = sasvi.SVIClient(
base_url=base_url,
auth=auth,
max_retries=0,
)
result = no_retry.alerts.get(alert_id=alert_id)
For long retry tuning, see Performance.
A write failed with outcome_unknown=True. Did it go through?
The SDK does not know, and says so. NetworkError.outcome_unknown is False
when the request never left the client (connect error, pool timeout, token fetch
failed), and resending is safe. It is True when the request went out and no
complete response came back, so the server may have applied it.
Writes that carry If-Match are not resent after an uncertain failure or a 5xx.
A resend would carry the old ETag, and a write that had succeeded would come back
as a 412. Read the resource again, check whether your change is there, and write
again only when it is not. The full table is in
Performance.
Why is --debug separate from --verbose in the CLI?
--verbose enables SDK HTTP wire logging. --debug prints the Python traceback on
any classified error. Either is independently useful: reach for --verbose when the
SDK's own configuration is in doubt, and --debug when the bug is in your script.
Where does the cached CLI token live?
$XDG_CONFIG_HOME/sasvi/token.json (default ~/.config/sasvi/token.json), mode 0600
with the parent directory 0700. A login made for a named profile goes to
token-<profile>.json in the same directory. Set SASVI_TOKEN_FILE=/absolute/path.json to
move the default file. See the CLI guide.
When to ask
If your question isn't covered here, in Troubleshooting, or in the relevant guide, open an issue with:
sasvi --json doctoroutput.- The smallest reproducible Python snippet.
- The full exception chain.
Go further
- Troubleshooting. Symptom, cause, fix.
- Errors reference. The typed exception hierarchy.