SDKs
The Policy platform now has official SDKs for the most common execution use cases. These packages are execution-focused clients for running stored policies and flows with API keys.
Available SDKs
Section titled “Available SDKs”| Language | Package | Install |
|---|---|---|
| Go | go-sdk | go get github.com/policies2/go-sdk |
| Python | policies2 | pip install policies2 |
| TypeScript | @policies2/sdk | npm install @policies2/sdk |
| Rust | policies | cargo add policies |
What They Cover
Section titled “What They Cover”These SDKs are intended for execution flows:
- execute stored policies
- execute stored flows
- authenticate with API keys
- use REST, and where supported, gRPC
They are not intended for policy authoring or administration. For creating, updating, publishing, ownership, and audit workflows, use the platform APIs directly.
Choose A Package
Section titled “Choose A Package”- Use
go-sdkif your service is written in Go and you want a native client for REST or gRPC execution. - Use
policies2if you want the Python package published to PyPI under thepolicies2name. - Use
@policies2/sdkif you are integrating from Node.js, Bun, or TypeScript applications. - Use
policiesif you want the Rust crate published on crates.io.
Example: Sanctions Screening
Section titled “Example: Sanctions Screening”These examples show a stored policy that decides whether a screening passes sanctions screening. Replace your-policy-id with a published policy ID and set POLICY_API_KEY in your environment.
TypeScript
Section titled “TypeScript”import { ExecutionClient } from "@policies2/sdk";
const client = new ExecutionClient({ apiKey: process.env.POLICY_API_KEY!, transport: { kind: "rest", baseUrl: "https://api.policy2.net" },});
const result = await client.executePolicy({ id: "your-policy-id", // replace with your published policy ID reference: "base", data: { screening: { sanctions_match: false, country: "GB", }, },});
if (result.result) { console.log("customer passed sanctions screening");} else { console.log("customer requires sanctions review");}package main
import ( "context" "fmt" "os"
policysdk "github.com/policies2/go-sdk")
func main() { client, err := policysdk.NewExecutionClient(policysdk.Config{ APIKey: os.Getenv("POLICY_API_KEY"), Transport: policysdk.TransportConfig{ Kind: policysdk.TransportKindREST, BaseURL: "https://api.policy2.net", }, }) if err != nil { panic(err) }
response, err := client.ExecutePolicy(context.Background(), policysdk.ExecutePolicyRequest{ ID: "your-policy-id", Reference: policysdk.ReferenceBase, Data: map[string]any{ "screening": map[string]any{ "sanctions_match": false, "country": "GB", }, }, }) if err != nil { panic(err) }
if response.Result { fmt.Println("customer passed sanctions screening") } else { fmt.Println("customer requires sanctions review") }}Python
Section titled “Python”from policies2 import ExecutionClient, ExecutionClientConfig, Reference, TransportConfig
client = ExecutionClient( ExecutionClientConfig( api_key="your-api-key", transport=TransportConfig(base_url="https://api.policy2.net"), ))
result = client.execute_policy( policy_id="your-policy-id", reference=Reference.BASE, data={ "screening": { "sanctions_match": False, "country": "GB", } },)
if result.result: print("customer passed sanctions screening")else: print("customer requires sanctions review")use policies::{ ExecutionClient, ExecutionClientConfig, ExecutePolicyRequest, Reference, TransportConfig, TransportKind,};use serde_json::json;
#[tokio::main]async fn main() -> Result<(), Box<dyn std::error::Error>> { let client = ExecutionClient::new(ExecutionClientConfig { api_key: std::env::var("POLICY_API_KEY")?, transport: TransportConfig { kind: TransportKind::Rest, base_url: Some("https://api.policy2.net".into()), address: None, tls: false, }, timeout: None, user_agent: None, })?;
let response = client .execute_policy(ExecutePolicyRequest { id: "your-policy-id".into(), reference: Reference::Base, data: json!({ "screening": { "sanctions_match": false, "country": "GB" } }), }) .await?;
if response.result { println!("customer passed sanctions screening"); } else { println!("customer requires sanctions review"); }
Ok(())}