Client¶
forward_sdk._sync.client.ForwardClient ¶
Bases: GeneratedServices
Talks to a Forward Networks instance.
Authentication is HTTP basic. Use an API token: its access key is the username and its secret is the password. A login name and password also work, but are subject to two-factor authentication and account lockout.
One client holds one connection pool, so reuse it rather than creating one per call. It is bound to the event loop it was created on.
Services hang off the client by group: client.networks,
client.snapshots, client.devices, client.device_tags and
client.nqe are hand-written for the paths integrations use most; the
remaining groups (client.checks, client.path_search,
client.aliases and so on) are generated from Forward's API description,
and their method names are the operation ids in Python casing.
Example
with ForwardClient.from_env() as client: ... networks = client.networks.list()
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
base_url
|
str
|
The instance URL, with or without a trailing |
required |
username
|
str | None
|
API token access key, or a login name. |
None
|
password
|
str | None
|
API token secret, or a password. |
None
|
verify
|
bool | str
|
TLS verification. Disable only for a deployment using a self-signed certificate, and prefer passing a CA bundle path. |
True
|
timeout
|
Timeout | float | None
|
A full |
None
|
retries
|
RetryPolicy | int | None
|
A :class: |
None
|
rate_limit_rpm
|
int | Literal['auto'] | None
|
Client-side pacing. |
'auto'
|
network_id
|
str | None
|
Default network for calls that omit one. |
None
|
snapshot_id
|
str | None
|
Default snapshot. |
None
|
user_agent
|
str | None
|
Identifies your application in the |
None
|
transport
|
BaseTransport | None
|
An |
None
|
throttle
|
Throttle | None
|
A custom pacer, for coordinating across processes. |
None
|
hooks
|
Hooks | None
|
Callbacks around each request. |
None
|
counters_raw
property
¶
counters_raw: Counters
The live counters, for readings that are not a flat record.
:meth:Counters.status_classes in particular, which is a mapping and
so does not belong in the snapshot's scalars.
from_env
classmethod
¶
from_env(
environ: Mapping[str, str] | None = None,
**overrides: Any,
) -> ForwardClient
Build a client from FORWARD_* environment variables.
environ replaces os.environ as the source, for a caller that
translates its own variable names first.
Reads FORWARD_URL, FORWARD_USERNAME, FORWARD_PASSWORD,
FORWARD_NETWORK_ID, FORWARD_SNAPSHOT_ID, FORWARD_VERIFY_TLS,
FORWARD_TIMEOUT, FORWARD_RETRIES, FORWARD_RATE_LIMIT_RPM and
FORWARD_USER_AGENT. Keyword arguments win over the environment.
call ¶
call(operation_id: str, /, **arguments: Any) -> Any
Call any operation by its operationId, with the generated methods' keywords.
For callers that choose the operation at run time, such as a configuration
tool driven by data. Arguments are the snake_case names the generated
service methods use (network_id, snapshot_id, ...), plus body
for a request body. network_id and snapshot_id fall back to the
client's defaults when the operation takes them.
Returns the decoded JSON, the response text when it is not JSON, or
None for an empty response. Streaming operations are refused: use
the service method that streams.
Raises:
| Type | Description |
|---|---|
ForwardConfigurationError
|
Unknown |
access ¶
access(
network_id: str | None = None,
*,
refresh: bool = False,
table: RoleTable | None = None,
) -> Access
What the calling account may do, from the roles Forward reports for it.
One call to GET /users/current, then answers from Forward's own role
table: (client.access("101")).may("NetworkOperation.
TRIGGER_SNAPSHOT_COLLECTION"). The roles are read once and kept on this
client; refresh=True reads them again after a role change.
That endpoint is unpublished, and some accounts are refused it (403) or find
it absent (404). Neither raises: the result answers None to everything
and says why, so a refusal to read the roles is never mistaken for a refusal
of the operation. Bad credentials and server errors still raise. See
:mod:forward_sdk.access for what True, False and None mean, and
:mod:forward_sdk.rbac for supplying the role table (table= here, or the
environment).
forward_sdk._sync.services.networks.NetworksService ¶
Bases: Service
Networks, and the workspaces forked from them.
get ¶
get(network_id: str) -> Network
Read one network by id.
Uses Forward's single-network read where it exists (after 26.10). Older Forward answers that path with 405 (or 404 "No endpoint"), and then the network list is filtered instead, so this works against both.
create ¶
create(name: str, *, note: str | None = None) -> Network
Create a network.
Forward's create endpoint takes only a name, so a note is applied as a follow-up update.
update ¶
update(network_id: str, **changes: Any) -> Network
Change a network's name, note or retention.
create_workspace ¶
create_workspace(
network_id: str | None = None,
*,
name: str | None = None,
retention_days: int | None = None,
devices: Sequence[str] | None = None,
cloud_accounts: Sequence[str] | None = None,
vcenters: Sequence[str] | None = None,
omissions: Sequence[str] | None = None,
) -> Network
Fork a network into a workspace for what-if changes.
Omit devices, cloud_accounts and vcenters to fork every source in the
parent network. Pass any of them to scope the workspace to a subset instead --
useful for a change window that only touches a handful of devices. At least one
of the three is required by the API if any is passed at all.
ensure_locations ¶
ensure_locations(
locations: Mapping[
str, NewLocation | Mapping[str, Any]
],
*,
network_id: str | None = None,
) -> dict[str, Location]
Make sure each named location exists with these fields; idempotent by name.
locations maps a location's name to its fields (lat and lng
at least, plus city, country, admin_division), as a mapping
(Python or wire names) or a :class:~forward_sdk.models.NewLocation.
Every entry is checked before anything is sent; a bad one raises
ValueError. Names match as Forward matches them, trimmed and
ignoring case. A name the network lacks is created; one it has is
patched only in the fields that differ, so a second run sends only the
read. Returns every named location as Forward holds it, by the name
given.
set_device_locations ¶
set_device_locations(
devices: Mapping[str, str],
*,
network_id: str | None = None,
) -> None
Place devices at locations, by location NAME: {"edge-1": "Dayton DC"}.
Names match as Forward matches them, trimmed and ignoring case. An
unknown name raises ValueError before anything is sent (create it
with :meth:ensure_locations first). Forward places only devices it
knows as collection sources, so on an upload-only network register them
first with :meth:register_devices:
otherwise Forward refuses the whole update with a 400 whose
error.unrecognized_devices names them.
Sends one atlas update. Repeating
it changes nothing more, but the first call pins a device that a
dynamic (glob) rule had placed, as Forward does for any move.
create_classic_device_with_api_key ¶
create_classic_device_with_api_key(
credential: Mapping[str, Any] | Any,
device: Mapping[str, Any] | Any,
*,
network_id: str | None = None,
) -> ClassicDeviceWithCredential
Create an API_KEY HTTP credential, then a classic device that uses it.
For connection types whose HTTP credential is an API key, such as
k8s_cni_control_plane_api (the key is the cluster's bearer token).
credential is a NewHttpCredential or its dict without a
username; its type is set to API_KEY. device is a
NewClassicDevice or its dict; its HTTP credential is set to the new
credential's id, so leave it out. A dict may name each field by its
Python name (login_type) or Forward's (loginType); Forward is
sent its own. Keys the model does not describe are sent unchanged.
Not atomic: if creating the device fails, the credential stays. The
error raised then carries it as error.http_credential, so it can be
deleted or reused. Mirrors the Go SDK's CreateWithAPIKey (v0.8.55);
composed from two existing writes and not run against a live Forward.
Raises:
| Type | Description |
|---|---|
ValueError
|
|
TypeError
|
An argument is neither a request model nor a mapping. |
register_devices ¶
register_devices(
devices: Sequence[str] | Mapping[str, str],
*,
network_id: str | None = None,
) -> builtins.list[str]
Register devices as classic devices that Forward never collects from.
For a network fed only by snapshot uploads, which has no collection
sources: Forward places only devices it knows as classic devices, so
:meth:set_device_locations refuses the rest (error.unrecognized_devices).
Each is created with collect false and no credentials, in one request.
Devices the network already has (matched by name, ignoring case) are
left alone, so a second run sends only the read.
devices is a list of names, each also used as its host, or a
mapping of name to host. Before anything is sent, a name Forward would
refuse (letters, digits, _, . and - only), two names that
differ only in case, and a host that is not a valid IP address or
hostname are all refused; a name that is not a valid hostname, such as
r1., needs the mapping form. Forward adds the batch all or nothing,
and also refuses a name another kind of source already uses (only
classic devices are skipped here). Returns the names registered.
forward_sdk._sync.services.snapshots.SnapshotsService ¶
Bases: Service
List, inspect, upload and wait on snapshots.
clear_cache ¶
clear_cache() -> None
Forget any cached snapshot resolution.
Call this when something you did makes "latest" mean something new and the SDK cannot know: an upload from another process, or a snapshot that finished processing while this client was running. Uploading through this client clears it for you.
list ¶
list(
network_id: str | None = None,
*,
state: str
| SnapshotState
| Sequence[str]
| None = None,
limit: int | None = None,
include_archived: bool = False,
include_predicted: bool = False,
exclude_triggers: Sequence[str] = (),
**filters: Any,
) -> list[SnapshotInfo]
List a network's snapshots, newest first.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
include_predicted
|
bool
|
Also list the snapshots Predict created. Forward
26.11 leaves them out unless asked; older Forward lists them
either way, so filter with |
False
|
exclude_triggers
|
Sequence[str]
|
Drop snapshots whose |
()
|
latest_processed ¶
latest_processed(
network_id: str | None = None,
*,
include_predicted: bool = False,
) -> SnapshotInfo | None
The most recent fully processed snapshot, or None if there is none.
Uses the snapshot listing rather than Forward's dedicated endpoint, which it deprecated.
"Latest" means newest by creation, the rule Forward applies for its own
latest snapshot (the UI, fwdctl). It is not the one that finished
processing last: reprocessing an older snapshot rebuilds it in place
and moves its processedAt forward, so ordering by that would hand
back an old snapshot over a newer processed one. The listing's order is
not documented, so this sorts what comes back rather than taking the
first row. Drafts and forks (a snapshot with a parentSnapshotId)
are never considered, as in Forward (SnapshotService.
getLatestProcessedSnapshot: newest first, no drafts or forks, the
first PROCESSED; the same at the primary, stable and master builds
the Go SDK checked). Predictions are forks too, so
include_predicted is the one place this goes beyond Forward's rule.
Predicted snapshots are excluded by default. Forward creates one for every Predict run, and they are processed like any other, so on a network using Predict the newest processed snapshot is very often a prediction rather than a state the network was ever in. Basing a change set on one predicts a change against a change.
The filter excludes PREDICT rather than requiring COLLECTION,
and the difference matters. A reprocessed snapshot reports
REPROCESS and is real collected data; reprocessing is how a changed
query or feature flag is picked up. Requiring COLLECTION would skip
it and silently select the previous collection, which during a
rehearsal is the snapshot taken while the change was still applied.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
include_predicted
|
bool
|
Consider predicted snapshots too. Forward does
not publish |
False
|
latest_collected_id ¶
latest_collected_id(
network_id: str | None = None,
*,
scan_limit: int = 10,
include_tags: Sequence[str] = (),
exclude_tags: Sequence[str] = (),
include_match: str = "any",
where: str = "",
) -> str
Find the newest snapshot that actually contains collected devices.
A snapshot can be processed and still hold nothing useful, for instance when collection failed for every device in scope. Callers that need real data (a sync job, say) want this rather than simply the latest processed snapshot. Each candidate is probed with a one-row query.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
scan_limit
|
int
|
How many recent snapshots to probe before giving up. |
10
|
include_tags
|
Sequence[str]
|
Only count devices carrying one of these tags. |
()
|
exclude_tags
|
Sequence[str]
|
Ignore devices carrying any of these tags. |
()
|
include_match
|
str
|
Whether one included tag is enough, or all are needed. |
'any'
|
where
|
str
|
Extra NQE |
''
|
Raises:
| Type | Description |
|---|---|
ForwardNotFoundError
|
If no scanned snapshot has devices in scope. |
metrics ¶
metrics(snapshot_id: str) -> Mapping[str, Any]
Collection and processing counts for a snapshot.
Raises:
| Type | Description |
|---|---|
ForwardNotFoundError
|
If the snapshot has no metrics, which is how
Forward answers for one that is unprocessed, still processing
or predicted. A loop over :meth: |
is_complete ¶
is_complete(snapshot_id: str) -> bool
Whether a snapshot collected and processed everything without failures.
invalidate ¶
invalidate(
snapshot_id: str, *, reprocess: bool = False
) -> SnapshotStateChange
Discard a snapshot's model so its collected data is processed again.
The snapshot keeps its id: reprocessing rebuilds it in place under the
org's current settings, which is how a parser or modelling change
reaches data already collected. Until processing finishes it cannot
answer queries, and if it is the network's only processed snapshot the
network has none in the meantime. Nothing here waits; follow with
:meth:wait_until_processed.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
reprocess
|
bool
|
Request processing now rather than when the snapshot is next needed. |
False
|
reprocess ¶
reprocess(
snapshot_id: str, *, invalidate: bool = True
) -> SnapshotStateChange
Rebuild a snapshot's model in place from its collected data.
By default this invalidates and requests processing in one call. Pass
invalidate=False for a snapshot already invalidated; Forward refuses
to reprocess one that is not.
upload ¶
upload(
files: str | Path | Sequence[str | Path],
*,
network_id: str | None = None,
note: str | None = None,
process: bool = True,
wait: bool = False,
on_progress: ProgressCallback | None = None,
) -> SnapshotInfo
Upload snapshot archives into a network.
The archives are streamed from disk, so their size does not matter to memory.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
files
|
str | Path | Sequence[str | Path]
|
One or more |
required |
process
|
bool
|
Build the network model after importing. |
True
|
wait
|
bool
|
Hold the request open until the import finishes. By default
Forward answers as soon as the upload lands and continues in the
background; poll with :meth: |
False
|
on_progress
|
ProgressCallback | None
|
Called as |
None
|
files ¶
files(snapshot_id: str) -> Sequence[str]
List every raw file Forward stored for a snapshot.
Unlike a device's own files (client.devices.files()), a raw file
need not belong to a modeled device -- a cloud provider's metadata for
an object no device represents, for instance. Useful for an
integration that needs artifacts a device-scoped read cannot reach.
file ¶
file(snapshot_id: str, file_name: str) -> str
Fetch one raw file stored for a snapshot. Raises 404 if it has none by that name.
file_excerpts ¶
file_excerpts(
snapshot_id: str,
file_name: str,
ranges: Sequence[tuple[int, int]],
) -> SnapFileExcerpts
Read line ranges of one raw file without fetching the rest.
file_name is "<device>,<file>" as files() lists it. Ranges are
0-based and inclusive; they must not overlap (Forward answers 400) and a
start past the end of the file is a 400, while an end past it is cut
short. Many ranges go in the request body instead of the URL.
file_info ¶
file_info(
snapshot_id: str, file_name: str
) -> SnapStoredFileInfo
One raw file's id, name, creation time and size, without its content.
file_access ¶
file_access(
network_id: str | None = None,
*,
snapshot_id: str | None = None,
) -> SnapDeviceAccessInfo
Which devices' collected files the caller may read.
action ALLOW means only the listed devices, BLOCK every device
but the listed ones, so BLOCK with no devices is full access.
search_file ¶
search_file(
snapshot_id: str, file_name: str, query: str
) -> Sequence[int]
The 0-based lines of a raw file containing query, ignoring case.
A line with several matches is repeated once per match.
exceptions ¶
exceptions(snapshot_id: str) -> Sequence[SnapshotException]
Exceptions Forward raised while processing a snapshot, grouped.
Identical stack traces are merged, with how often each was raised and
which devices raised it. PARSING and MODELING exceptions belong
to devices; the other types are snapshot-wide and name no device.
Parser-equivalence failures are reported here too.
Unpublished. Needs the network's DEBUG_SNAPSHOTS permission.
exceptions_text ¶
exceptions_text(snapshot_id: str) -> str
The same exceptions as one plain-text dump, ungrouped.
One stack trace per device failure and per snapshot-generation failure, each headed by the device name or an index. Empty when there were none.
collection_exceptions ¶
collection_exceptions(
snapshot_id: str,
*,
limit: int | None = None,
occurrences_limit: int | None = None,
) -> AnalysisCollectionExceptions
What went wrong while collecting a snapshot, merged by stack trace.
Unpublished. Collection, as opposed to the processing that
:meth:exceptions reports.
progress ¶
progress(snapshot_id: str) -> AnalysisSnapshotProgress
The latest progress report for a snapshot that is still being processed.
process_estimate ¶
process_estimate(
snapshot_id: str,
) -> AnalysisProcessEstimate
Forward's estimate of how long processing a snapshot will take.
processing_queue ¶
processing_queue() -> AnalysisSnapshotProcessingQueue
The snapshots waiting for, and being given, processing capacity.
collection_log ¶
collection_log(snapshot_id: str) -> Iterator[bytes]
The collection log of a snapshot, streamed as plain text.
logs ¶
logs(
snapshot_id: str,
*,
device_name: str | None = None,
level: str | None = None,
backfilled: bool | None = None,
) -> Iterator[bytes]
A snapshot's processing logs, streamed as plain text.
They are large: one live snapshot's came to hundreds of megabytes. Narrow
them with device_name or level before reading.
favorite ¶
favorite(snapshot_id: str) -> None
Keep a snapshot out of the network's automatic retention clean-up.
set_note ¶
set_note(snapshot_id: str, note: str) -> Mapping[str, Any]
Replace a snapshot's note. Returns the snapshot's metadata.
retention_policy ¶
retention_policy(
network_id: str | None = None,
) -> SnapshotRetentionPolicy
How many snapshots of each age Forward keeps for a network.
set_retention_policy ¶
set_retention_policy(
policy: SnapshotRetentionPolicy | Mapping[str, Any],
network_id: str | None = None,
) -> None
Replace a network's retention policy. Every field is required.
preview_retention ¶
preview_retention(
network_id: str | None = None,
) -> SnapshotRetentionPreview
Which snapshots the current policy would remove, without removing any.
export ¶
export(
snapshot_id: str,
*,
only: str | None = None,
include_devices: Sequence[str] | None = None,
exclude_devices: Sequence[str] | None = None,
obfuscation_key: str | None = None,
obfuscate_names: bool | None = None,
on_progress: ProgressCallback | None = None,
) -> Iterator[bytes]
Download a snapshot archive in chunks.
With none of the device or obfuscation arguments this is the whole snapshot. Any of them selects Forward's subset export instead.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
only
|
str | None
|
Restrict the export, for example to |
None
|
include_devices
|
Sequence[str] | None
|
Export only these devices. Globs such as |
None
|
exclude_devices
|
Sequence[str] | None
|
Export everything except these devices. |
None
|
obfuscation_key
|
str | None
|
Obfuscate sensitive data, keyed by this value. |
None
|
obfuscate_names
|
bool | None
|
Also obfuscate names. Needs |
None
|
on_progress
|
ProgressCallback | None
|
Called as |
None
|
Raises:
| Type | Description |
|---|---|
ForwardConfigurationError
|
If the arguments contradict each other. |
download ¶
download(
snapshot_id: str, destination: str | Path, **kwargs: Any
) -> Path
Download a snapshot archive to a file.
wait_until_processed ¶
wait_until_processed(
snapshot_id: str,
*,
network_id: str | None = None,
poll_interval: float = DEFAULT_POLL_INTERVAL,
timeout: float | None = 3600.0,
on_poll: Callable[[SnapshotInfo, float], None]
| None = None,
) -> SnapshotInfo
Poll until a snapshot finishes processing.
Forward has no endpoint for a single snapshot, so this watches the network's snapshot listing.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
on_poll
|
Callable[[SnapshotInfo, float], None] | None
|
Called as |
None
|
Raises:
| Type | Description |
|---|---|
ForwardExecutionError
|
Processing ended in a failure state. |
ForwardTimeoutError
|
|
ForwardNotFoundError
|
The snapshot is not in the network's listing. |
collect ¶
collect(
network_id: str | None = None,
*,
wait: bool = True,
start: bool = True,
timeout: float | None = 3600.0,
poll_interval: float = 10.0,
snapshot_timeout: float = 120.0,
on_poll: Callable[[CollectorTask, float], None]
| None = None,
) -> CollectionRun
Start a network collection and, by default, wait for its snapshot.
This is the collector-task API: collector_tasks.add_collector_task
and get_collector_task put together. The task carries no snapshot id,
so the new snapshot is the one that appears in the network's listing
once the task succeeds; predictions are ignored, since a change
rehearsal may create one meanwhile. Forward marks the task SUCCEEDED
and then creates the snapshot in the same step, so it is listed within
moments (snapshot_timeout allows two minutes). It can create one
even when the task ended FAILED, because every device failed; the
error does not look for it.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
wait
|
bool
|
Poll until the task finishes. With |
True
|
start
|
bool
|
With |
True
|
timeout
|
float | None
|
Give up waiting after this many seconds. The collection carries on in Forward. |
3600.0
|
poll_interval
|
float
|
Seconds between looks at the task. |
10.0
|
snapshot_timeout
|
float
|
After the task succeeds, how long to wait for its snapshot to be listed. |
120.0
|
on_poll
|
Callable[[CollectorTask, float], None] | None
|
Called as |
None
|
Raises:
| Type | Description |
|---|---|
ForwardExecutionError
|
The task failed, timed out or was cancelled, or it succeeded but no new snapshot appeared. |
ForwardTimeoutError
|
|
compute_advanced_reachability ¶
compute_advanced_reachability(
snapshot_id: str,
) -> Mapping[str, Any]
Start advanced reachability computation for a snapshot.
start_reachability_job ¶
start_reachability_job(
snapshot_id: str, *, network_id: str | None = None
) -> ReachabilityJob
Start reachability computation as a pollable job.
Unpublished: these endpoints are outside Forward's documented API, though
stable and safe to use. :meth:compute_advanced_reachability is the
published equivalent, without progress polling.
forward_sdk._sync.services.devices.DevicesService ¶
Bases: Service
Read the devices Forward collected.
Note that tags and locationId are absent from a device unless
requested through with_. Their absence means "not requested", never
"none set".
list ¶
list(
network_id: str | None = None,
*,
snapshot_id: str | None = None,
skip: int | None = None,
limit: int | None = None,
with_: Sequence[str] | None = None,
**filters: Any,
) -> list[Device]
List devices, optionally filtered by vendor, model, platform and so on.
iter ¶
iter(
network_id: str | None = None,
*,
snapshot_id: str | None = None,
page_size: int = DEFAULT_PAGE_SIZE,
with_: Sequence[str] | None = None,
**filters: Any,
) -> Iterator[Device]
Iterate every device, fetching a page at a time.
Useful for large networks, where one unbounded response would be slow to arrive and large to hold.
get ¶
get(
device_name: str,
*,
network_id: str | None = None,
snapshot_id: str | None = None,
with_: Sequence[str] | None = None,
) -> Device
Fetch one device by name.
files ¶
files(
device_name: str,
*,
network_id: str | None = None,
snapshot_id: str | None = None,
) -> Any
List the files collected from a device.
file ¶
file(
device_name: str,
file_name: str,
*,
network_id: str | None = None,
snapshot_id: str | None = None,
) -> str
Fetch one collected file, such as a running configuration.
missing ¶
missing(
network_id: str | None = None,
*,
snapshot_id: str | None = None,
) -> Any
List devices the network expects but the snapshot does not contain.
upsert_classic ¶
upsert_classic(
devices: Sequence[Mapping[str, Any]],
*,
network_id: str | None = None,
with_: Sequence[str] = (),
) -> Sequence[ClassicDevice]
Add or update classic devices by name, and return them as stored.
Forward's batch upsert, classic_devices.put_classic_devices(),
answers 201 with nothing worth reading, so a caller who wants to confirm
what was written has to read the devices back by name. This does that
in one call: the upsert, then a batch read of exactly the names sent.
Applying the same manifest twice is a no-op on Forward's side, and the
second call returns the same devices.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
devices
|
Sequence[Mapping[str, Any]]
|
The device definitions, the same bodies the upsert takes.
Each needs a |
required |
with_
|
Sequence[str]
|
Extra fields to include on the read back, such as |
()
|
forward_sdk._sync.services.device_tags.DeviceTagsService ¶
Bases: Service
Read and change the tags applied to devices.
Tags are how most integrations scope a sync, so both the tag list and each tag's device membership are available.
list ¶
list(
network_id: str | None = None,
*,
with_devices: bool = False,
snapshot_id: str | None = None,
) -> list[dict[str, Any]]
List every tag, optionally with the devices carrying each one.
snapshot_id reads the devices that carried each tag as of that
snapshot rather than now; only the form with devices takes one, so it
needs with_devices=True.
get ¶
get(
tag_name: str,
*,
network_id: str | None = None,
with_devices: bool = False,
) -> dict[str, Any]
Fetch one tag.
create ¶
create(
tag: Mapping[str, Any], *, network_id: str | None = None
) -> dict[str, Any]
Create a tag.
create_many ¶
create_many(
tags: Sequence[Mapping[str, Any]],
*,
network_id: str | None = None,
) -> Any
Create several tags in one request.
add_to_devices ¶
add_to_devices(
tag_name: str,
devices: Sequence[str],
*,
network_id: str | None = None,
) -> Any
Apply one tag to a set of devices.
remove_from_devices ¶
remove_from_devices(
tag_name: str,
devices: Sequence[str],
*,
network_id: str | None = None,
) -> Any
Remove one tag from a set of devices.
add_tags_to_devices ¶
add_tags_to_devices(
body: Any,
*,
network_id: str | None = None,
snapshot_id: str | None = None,
) -> Any
Apply several tags to several devices in one request.
snapshot_id makes the change take effect from that snapshot, so an
NQE read of it (device.tagNames) shows it at once; without one it
shows from the next snapshot. With a snapshot, Forward checks the device
names against that snapshot's devices and endpoints rather than the
network's collection sources.
remove_tags_from_devices ¶
remove_tags_from_devices(
body: Any,
*,
network_id: str | None = None,
snapshot_id: str | None = None,
) -> Any
Remove several tags from several devices in one request.
snapshot_id makes the change take effect from that snapshot, so an
NQE read of it (device.tagNames) shows it at once; without one it
shows from the next snapshot. With a snapshot, Forward checks the device
names against that snapshot's devices and endpoints rather than the
network's collection sources.
remove_all_from_devices ¶
remove_all_from_devices(
devices: Sequence[str],
*,
network_id: str | None = None,
snapshot_id: str | None = None,
) -> Any
Strip every tag from a set of devices.
snapshot_id makes the change take effect from that snapshot, so an
NQE read of it (device.tagNames) shows it at once; without one it
shows from the next snapshot. With a snapshot, Forward checks the device
names against that snapshot's devices and endpoints rather than the
network's collection sources.
replace_all_for_devices ¶
replace_all_for_devices(
body: Any,
*,
network_id: str | None = None,
snapshot_id: str | None = None,
) -> Any
Replace the full tag set of the given devices.
snapshot_id makes the change take effect from that snapshot, so an
NQE read of it (device.tagNames) shows it at once; without one it
shows from the next snapshot. With a snapshot, Forward checks the device
names against that snapshot's devices and endpoints rather than the
network's collection sources.
forward_sdk.config.ClientConfig
dataclass
¶
Resolved settings for one client.
Attributes:
| Name | Type | Description |
|---|---|---|
base_url |
str
|
API root, always ending in |
username |
str | None
|
API token access key, or a login name. |
password |
str | None
|
API token secret, or a password. |
verify |
bool | str
|
TLS verification: |
timeout |
Timeout
|
Per-request timeouts. |
stream_read_timeout |
float
|
Read timeout for streaming responses. |
retries |
RetryPolicy
|
Retry policy. |
rate_limit_rpm |
int | None
|
Client-side pacing in requests per minute, or |
network_id |
str | None
|
Default network for calls that omit one. |
snapshot_id |
str | None
|
Default snapshot for calls that omit one. |
user_agent |
str | None
|
Extra token identifying the calling application. |
cache_ttl |
float
|
Seconds to reuse cached reads, or |
snapshot_cache_ttl |
float | Literal['lifetime']
|
How long to reuse a resolved snapshot. |
forward_sdk.config.RetryPolicy
dataclass
¶
How the transport retries a failed request.
Attributes:
| Name | Type | Description |
|---|---|---|
max_attempts |
int
|
Total sends, including the first. |
backoff_base |
float
|
Starting delay in seconds for exponential backoff. |
backoff_cap |
float
|
Upper bound on the computed backoff, before jitter. |
max_retry_after |
float
|
Upper bound on an honoured |
coerce
classmethod
¶
coerce(value: RetryPolicy | int | None) -> RetryPolicy
Accept a policy, a plain retry count, or None for the default.
forward_sdk.telemetry.Hooks ¶
Callbacks invoked around each request.
Subclass and override only what you need; every method defaults to doing nothing. Hooks run inline on the calling thread, so they should be cheap. A hook that raises is logged and ignored rather than failing the request it was observing.
on_request ¶
on_request(
operation: OpDef | None, request: Request
) -> None
Called immediately before a request is sent, once per attempt.
on_response ¶
on_response(
operation: OpDef | None,
response: Response,
elapsed: float,
) -> None
Called after a response is received, including error responses.
on_retry ¶
on_retry(
operation: OpDef | None,
attempt: int,
delay: float,
reason: str,
) -> None
Called before sleeping between retries.
on_sleep ¶
on_sleep(seconds: float, reason: str) -> None
Called before any client-side pause, including rate-limit pacing.
forward_sdk.telemetry.CounterSnapshot
dataclass
¶
An immutable reading of a client's counters.
attempts_per_minute
property
¶
attempts_per_minute: float
Observed request rate, for comparison against a server-side limit.
Zero until at least two requests have been sent far enough apart to span a measurable window.
The window is measured from the first attempt to the most recent, so it
spans one fewer interval than there are attempts. Dividing by attempts
rather than intervals overstates the rate by n / (n - 1), which is
100% at two attempts and 5% at twenty. That matters when the result is
compared against a published ceiling, because the error is pessimistic
and can condemn a rate that is actually within the limit.