Documentation
PolicyCortex Cloud Governance SDKs: Python, Node.js & Go
PolicyCortex provides comprehensive SDKs and libraries for popular programming languages, enabling seamless integration with your existing applications and infrastructure. Build powerful governance workflows with type-safe APIs and extensive code examples.
Comprehensive Guide to PolicyCortex SDKs & Libraries
SDK Overview
🐍 Python SDK
Full-featured Python library with async support, type hints, and comprehensive error handling.
🟢 Node.js SDK
TypeScript-first Node.js SDK with Promise support and comprehensive TypeScript definitions.
🐹 Go SDK
Lightweight Go library with context support, structured error handling, and concurrent-safe operations.
Common Features
Core Capabilities
Developer Experience
Python SDK
Installation and Setup
Install the PolicyCortex Python SDK using pip. The SDK supports Python 3.8+ and includes type hints for improved development experience with modern IDEs.
# Install the latest version
pip install policycortex
# Install with async support (optional)
pip install policycortex[async]
# Install development version
pip install git+https://github.com/policycortex/python-sdk.gitBasic Usage
import policycortex
from policycortex import PolicyCortexClient
from policycortex.exceptions import PolicyCortexError
client = PolicyCortexClient(
api_key="sk_live_1234567890abcdef",
timeout=30
)
try:
policies = client.policies.list(
limit=50,
framework="soc2",
status="active"
)
print(f"Found {len(policies.data)} policies")
new_policy = client.policies.create({
"name": "S3 Public Read Prevention",
"description": "Prevents S3 buckets from being publicly readable",
"framework": ["soc2", "hipaa"],
"severity": "high",
"resource_types": ["aws_s3_bucket"]
})
print(f"Created policy: {new_policy.id}")
except PolicyCortexError as e:
print(f"API Error: {e.message}")🔧 Configuration
from policycortex import PolicyCortexClient
from policycortex.config import RetryConfig
client = PolicyCortexClient(
api_key="sk_live_1234567890abcdef",
base_url="https://api.policycortex.com/v1",
timeout=60,
retry_config=RetryConfig(
max_retries=3,
backoff_factor=2.0
)
)🧪 Testing
from policycortex.testing import MockClient
def test_policy_creation():
mock_client = MockClient()
mock_client.policies.create.return_value = {
"id": "pol_test123",
"name": "Test Policy"
}
policy = mock_client.policies.create({
"name": "Test Policy"
})
assert policy["id"] == "pol_test123"Node.js SDK
Installation and Setup
The PolicyCortex Node.js SDK provides first-class TypeScript support with comprehensive type definitions and modern JavaScript features including async/await and ES modules.
# Install with npm
npm install @policycortex/sdk
# Install with yarn
yarn add @policycortex/sdk
# Install with pnpm
pnpm add @policycortex/sdkTypeScript/JavaScript Usage
import { PolicyCortexClient } from '@policycortex/sdk';
const client = new PolicyCortexClient({
apiKey: 'sk_live_1234567890abcdef',
timeout: 30000
});
async function managePolicies() {
try {
const policies = await client.policies.list({
limit: 50,
framework: 'soc2',
status: 'active'
});
console.log(`Found ${policies.data.length} policies`);
const newPolicy = await client.policies.create({
name: 'EC2 Instance Encryption',
description: 'Ensures EC2 instances use encrypted EBS volumes',
framework: ['soc2', 'hipaa'],
severity: 'high',
resource_types: ['aws_instance']
});
console.log(`Created policy: ${newPolicy.id}`);
} catch (error) {
console.error('API Error:', error);
}
}
managePolicies();⚙️ Configuration
import { PolicyCortexClient } from '@policycortex/sdk';
const client = new PolicyCortexClient({
apiKey: process.env.POLICYCORTEX_API_KEY!,
baseURL: 'https://api.policycortex.com/v1',
timeout: 60000,
retries: 3,
userAgent: 'MyApp/1.0.0'
});🧪 Testing
import { MockClient } from '@policycortex/sdk/testing';
test('should create policy', async () => {
const client = new MockClient();
client.policies.create.mockResolvedValue({
id: 'pol_test123',
name: 'Test Policy'
});
const policy = await client.policies.create({
name: 'Test Policy'
});
expect(policy.id).toBe('pol_test123');
});Go SDK
Installation and Setup
The PolicyCortex Go SDK provides a lightweight, concurrent-safe client with context support and structured error handling, perfect for cloud-native applications and microservices.
# Install the SDK
go get github.com/policycortex/go-sdk
# Install specific version
go get github.com/policycortex/go-sdk@v1.2.3Go Usage Examples
package main
import (
"context"
"fmt"
"log"
"time"
"github.com/policycortex/go-sdk/policycortex"
"github.com/policycortex/go-sdk/policycortex/types"
)
func main() {
client := policycortex.NewClient(&policycortex.Config{
APIKey: "sk_live_1234567890abcdef",
Timeout: 30 * time.Second,
Retries: 3,
})
ctx := context.Background()
policies, err := client.Policies.List(ctx, &types.ListPoliciesRequest{
Limit: 50,
Framework: "soc2",
Status: "active",
})
if err != nil {
log.Fatalf("Failed to list policies: %v", err)
}
fmt.Printf("Found %d policies
", len(policies.Data))
newPolicy := &types.CreatePolicyRequest{
Name: "RDS Backup Retention",
Description: "Ensures RDS instances have proper backup retention",
Framework: []string{"soc2", "hipaa"},
Severity: "medium",
ResourceTypes: []string{"aws_db_instance"},
}
policy, err := client.Policies.Create(ctx, newPolicy)
if err != nil {
log.Fatalf("Failed to create policy: %v", err)
}
fmt.Printf("Created policy: %s
", policy.ID)
}⚙️ Configuration
package main
import (
"net/http"
"time"
"github.com/policycortex/go-sdk/policycortex"
)
func main() {
httpClient := &http.Client{
Timeout: 60 * time.Second,
}
client := policycortex.NewClient(&policycortex.Config{
APIKey: "sk_live_1234567890abcdef",
HTTPClient: httpClient,
UserAgent: "MyApp/1.0.0",
Retries: 3,
})
}🧪 Testing
package main
import (
"context"
"testing"
"github.com/policycortex/go-sdk/policycortex/testing"
)
func TestPolicyCreation(t *testing.T) {
mockClient := testing.NewMockClient()
expectedPolicy := &types.Policy{
ID: "pol_test123",
Name: "Test Policy",
}
mockClient.Policies.
On("Create", mock.Anything, mock.Anything).
Return(expectedPolicy, nil)
policy, err := mockClient.Policies.Create(
context.Background(),
&types.CreatePolicyRequest{
Name: "Test Policy",
},
)
if err != nil {
t.Fatal(err)
}
if policy.ID != "pol_test123" {
t.Errorf("Expected ID pol_test123, got %s", policy.ID)
}
}Command Line Interface
PolicyCortex CLI
The PolicyCortex CLI provides a powerful command-line interface for managing policies, running scans, and generating reports directly from your terminal or CI/CD pipelines.
# Install CLI globally
npm install -g @policycortex/cli
# Or install with Homebrew (macOS)
brew install policycortex/tap/policycortex
# Configure authentication
policycortex auth login
export POLICYCORTEX_API_KEY="sk_live_1234567890abcdef"
# List policies
policycortex policies list --framework soc2 --status active
# Create policy from file
policycortex policies create --file policy.yaml
# Run immediate scan
policycortex scans create \
--name "Emergency Security Scan" \
--type policy_specific \
--environment production
# Generate report
policycortex reports create \
--name "Monthly Compliance Report" \
--type compliance \
--framework soc2 \
--format pdf,excel📄 Configuration Files
# policy.yaml
name: "S3 Bucket Encryption"
description: "Ensures S3 buckets are encrypted"
framework:
- soc2
- hipaa
severity: high
resource_types:
- aws_s3_bucket🔄 CI/CD Integration
# .github/workflows/compliance.yml
name: Compliance Check
on: [push]
jobs:
compliance:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Install PolicyCortex CLI
run: npm install -g @policycortex/cli
- name: Run compliance scan
env:
POLICYCORTEX_API_KEY: ${{ secrets.POLICYCORTEX_API_KEY }}
run: |
policycortex scans create \
--name "CI Compliance Check" \
--waitCommunity & Support
📚 Resources
- • API Documentation
- • GitHub Repositories
- • Code Examples
- • SDK Changelog
- • Integration Guides
- • API Status Page
💬 Support Channels
- • Discord Community
- • GitHub Issues
- • Technical Support
- • SDK Team Email
- • Stack Overflow
- • Troubleshooting Guide