sift_client.resources.campaigns
¶
| CLASS | DESCRIPTION |
|---|---|
CampaignsAPIAsync |
High-level API for interacting with campaigns. |
CampaignsAPIAsync
¶
CampaignsAPIAsync(sift_client: SiftClient)
Bases: ResourceBase
High-level API for interacting with campaigns.
A campaign is a named list of reports. Runs join a campaign through the reports they
generate, so a run must be created with create_default_report=True to be added.
Initialize the CampaignsAPI.
| PARAMETER | DESCRIPTION |
|---|---|
sift_client
|
The Sift client to use.
TYPE:
|
| METHOD | DESCRIPTION |
|---|---|
get |
Get a Campaign by ID or client key. |
list_ |
List campaigns. |
find |
Find one campaign. Takes the same arguments as |
create |
Create a new campaign, optionally seeded with reports. |
get_or_create |
Get the campaign with this client key, or create it. |
update |
Update a Campaign. |
add_reports |
Add reports to a campaign, keeping the ones already there. |
add_runs |
Add runs to a campaign through the reports they generated. |
archive |
Archive a campaign. |
unarchive |
Unarchive a campaign. |
report_summaries |
Get per-report rule counts for several campaigns at once. |
| ATTRIBUTE | DESCRIPTION |
|---|---|
client |
TYPE:
|
grpc_client |
TYPE:
|
rest_client |
TYPE:
|
get
async
¶
get(
campaign_id: str | None = None,
*,
client_key: str | None = None,
organization_id: str | None = None,
skip_report_summaries: bool = False,
) -> Campaign
Get a Campaign by ID or client key.
| PARAMETER | DESCRIPTION |
|---|---|
campaign_id
|
The ID of the campaign.
TYPE:
|
client_key
|
The client key, as an alternative to the ID.
TYPE:
|
organization_id
|
Required with
TYPE:
|
skip_report_summaries
|
Omit the per-report counts. Much faster for large campaigns.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Campaign
|
The Campaign. |
list_
async
¶
list_(
*,
name: str | None = None,
names: list[str] | None = None,
name_contains: str | None = None,
name_regex: str | Pattern | None = None,
campaign_ids: list[str] | None = None,
client_keys: list[str] | None = None,
created_by: Any | str | None = None,
tags: list[str] | list[Tag] | None = None,
metadata: dict[str, Any] | None = None,
reports: list[Report] | list[str] | None = None,
runs: list[Run] | list[str] | None = None,
description_contains: str | None = None,
include_archived: bool = False,
filter_query: str | None = None,
order_by: str | None = None,
limit: int | None = None,
page_size: int | None = None,
) -> list[Campaign]
List campaigns.
| PARAMETER | DESCRIPTION |
|---|---|
name
|
Exact name of the campaign.
TYPE:
|
names
|
List of campaign names to filter by.
TYPE:
|
name_contains
|
Partial name of the campaign.
TYPE:
|
name_regex
|
Regular expression to filter campaigns by name.
TYPE:
|
campaign_ids
|
Filter to campaigns with any of these IDs.
TYPE:
|
client_keys
|
Filter to campaigns with any of these client keys.
TYPE:
|
created_by
|
Filter campaigns created by this user ID.
TYPE:
|
tags
|
Filter campaigns with any of these Tags or tag names.
TYPE:
|
metadata
|
Filter campaigns by metadata criteria.
TYPE:
|
reports
|
Filter campaigns containing any of these Reports or report IDs.
TYPE:
|
runs
|
Filter campaigns containing any of these Runs or run IDs.
TYPE:
|
description_contains
|
Partial description of the campaign.
TYPE:
|
include_archived
|
If True, include archived campaigns in results.
TYPE:
|
filter_query
|
Explicit CEL query to filter campaigns.
TYPE:
|
order_by
|
Field and direction to order results by.
TYPE:
|
limit
|
Maximum number of campaigns to return. If None, returns all matches.
TYPE:
|
page_size
|
Number of results to fetch per request.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
list[Campaign]
|
A list of Campaign objects that match the filter criteria. |
find
async
¶
find(**kwargs) -> Campaign | None
Find one campaign. Takes the same arguments as list_.
Raises if more than one matches.
| PARAMETER | DESCRIPTION |
|---|---|
**kwargs
|
Keyword arguments to pass to
DEFAULT:
|
| RETURNS | DESCRIPTION |
|---|---|
Campaign | None
|
The Campaign found or None. |
create
async
¶
create(
create: CampaignCreate | dict,
*,
reports: list[Report] | list[str] | None = None,
runs: list[Run] | list[str] | None = None,
from_campaign: str | Campaign | None = None,
) -> Campaign
Create a new campaign, optionally seeded with reports.
At most one seed may be given. runs lets the server collect the reports those
runs generated, so the runs need a default report.
| PARAMETER | DESCRIPTION |
|---|---|
create
|
The campaign definition.
TYPE:
|
reports
|
Seed with these Reports or report IDs.
TYPE:
|
runs
|
Seed with the reports these Runs generated.
TYPE:
|
from_campaign
|
Duplicate this Campaign or campaign ID.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Campaign
|
The created Campaign. |
get_or_create
async
¶
get_or_create(create: CampaignCreate | dict) -> Campaign
Get the campaign with this client key, or create it.
| PARAMETER | DESCRIPTION |
|---|---|
create
|
The campaign definition. Its
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Campaign
|
The existing or newly created Campaign. |
| RAISES | DESCRIPTION |
|---|---|
ValueError
|
If |
update
async
¶
update(
campaign: str | Campaign, update: CampaignUpdate | dict
) -> Campaign
Update a Campaign.
reports, tags, and metadata are replaced, not merged. Prefer add_reports
or add_runs to grow the report list.
| PARAMETER | DESCRIPTION |
|---|---|
campaign
|
The Campaign or campaign ID to update.
TYPE:
|
update
|
Updates to apply to the Campaign.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Campaign
|
The updated Campaign. |
add_reports
async
¶
add_runs
async
¶
Add runs to a campaign through the reports they generated.
A campaign holds reports, not runs, so each run must have a default report. Pass
create_default_report=True to RunCreate to get one.
| PARAMETER | DESCRIPTION |
|---|---|
campaign
|
The Campaign or campaign ID to add to.
TYPE:
|
runs
|
The Runs or run IDs to add.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Campaign
|
The updated Campaign. |
| RAISES | DESCRIPTION |
|---|---|
ValueError
|
If any run has no default report. |
archive
async
¶
unarchive
async
¶
report_summaries
async
¶
report_summaries(
campaigns: list[str | Campaign],
*,
organization_id: str | None = None,
) -> dict[str, list[CampaignReport]]
Get per-report rule counts for several campaigns at once.
| PARAMETER | DESCRIPTION |
|---|---|
campaigns
|
The Campaigns or campaign IDs to summarize.
TYPE:
|
organization_id
|
Required if you belong to several organizations.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
dict[str, list[CampaignReport]]
|
A mapping of campaign ID to its reports, with counts populated. The service |
dict[str, list[CampaignReport]]
|
returns each campaign's reports in no fixed order; |
dict[str, list[CampaignReport]]
|
orders them to match the campaign. |