Skip to main content

AZTP (Agentic Zero Trust Protocol) Client Library for Python

Project description

AZTP Client Python

Enterprise-grade identity service client for secure workload identity management using AZTP standards.


Table of Contents


Installation

pip install aztp-client

Requirements

  • Python 3.8 or higher

Trusted Domains

The AZTP client maintains a whitelist of trusted domains for use with the trustDomain parameter. If not specified, defaults to aztp.network.

from aztp_client import whiteListTrustDomains
print("Available trusted domains:", whiteListTrustDomains)

Current Trusted Domains:

  • gptarticles.xyz
  • gptapps.ai
  • vcagents.ai

Quick Start

from aztp_client import Aztp

client = Aztp(api_key="your-api-key")
agent = await client.secure_connect({}, "service1", config={"isGlobalIdentity": False})

Core Methods

Identity Management

Method Description
secure_connect(crew_agent, name, config) Create a secure connection for a workload
verify_identity(agent) Verify the identity of a secured agent
verify_identity_connection(from_aztp_id, to_aztp_id) Verify connection between two agents
get_identity(agent) Get identity information for a secured agent
discover_identity(trust_domain, requestor_identity) Discover identities based on parameters
revoke_identity(aztp_id, reason) Revoke an AZTP identity
reissue_identity(aztp_id) Restore a previously revoked identity

Policy Management

Method Description
get_policy(aztp_id) Get access policy for a specific AZTP identity
get_policy_value(policies, filter_key, filter_value) Filter and extract a specific policy statement
is_action_allowed(policy, action) Check if an action is allowed by a policy statement

Policy Statement Structure

  • The Statement field in a policy can be either a single dict or a list of dicts.
  • The Action field can be a string or a list of strings.
  • The is_action_allowed method normalizes both cases and works for all valid policy structures.

Example: Check if an action is allowed

policy_statement = aztpClient.get_policy_value(identity_access_policy, "code", "policy:0650537f8614")
if policy_statement:
    is_allowed = aztpClient.is_action_allowed(policy_statement, "read")
    print(f"Is 'read' allowed? {is_allowed}")

Example Policy Statement:

{
  "Statement": [
    {
      "Effect": "Allow",
      "Action": ["read", "write"]
    },
    {
      "Effect": "Deny",
      "Action": "delete"
    }
  ]
}

Examples

Identity Revocation and Reissue

import os
import asyncio
from aztp_client import Aztp, whiteListTrustDomains
from dotenv import load_dotenv

load_dotenv()

async def main():
    api_key = os.getenv("AZTP_API_KEY")
    base_url = os.getenv("AZTP_BASE_URL")
    if not api_key:
        raise ValueError("AZTP_API_KEY is not set")

    aztpClient = Aztp(api_key=api_key, base_url=base_url)
    agent = {}
    agent_name = "astha-local/arjun"

    # Secure Connect
    print(f"Connecting agent: {agent_name}")
    localTestAgent = await aztpClient.secure_connect(agent, agent_name, {"isGlobalIdentity": False})
    print("AZTP ID:", localTestAgent.identity.aztp_id)

    # Verify
    print(f"Verifying identity for agent: {agent_name}")
    verify = await aztpClient.verify_identity(localTestAgent)
    print("Verify:", verify)

    # Revoke identity
    print(f"Revoking identity for agent: {agent_name}")
    revoke_result = await aztpClient.revoke_identity(localTestAgent.identity.aztp_id, "Revoked by user")
    print("Identity Revoked:", revoke_result)

    # Verify after revoke
    print(f"Verifying identity after revoke for agent: {agent_name}")
    is_valid_after_revoke = await aztpClient.verify_identity(localTestAgent)
    print("Identity Valid After Revoke:", is_valid_after_revoke)

    # Reissue identity
    print(f"Reissuing identity for agent: {agent_name}")
    reissue_result = await aztpClient.reissue_identity(localTestAgent.identity.aztp_id)
    print("Identity Reissued:", reissue_result)

    # Verify after reissue
    print(f"Verifying identity after reissue for agent: {agent_name}")
    is_valid_after_reissue = await aztpClient.verify_identity(localTestAgent)
    print("Identity Valid After Reissue:", is_valid_after_reissue)

    # Get and display policy information
    print(f"Getting policy information for agent: {agent_name}")
    identity_access_policy = await aztpClient.get_policy(localTestAgent.identity.aztp_id)

    # Extract a specific policy by code (replace with your actual policy code)
    policy = aztpClient.get_policy_value(
        identity_access_policy,
        "code",
        "policy:0650537f8614"  # Replace with your actual policy code
    )

    if policy:
        is_allow = aztpClient.is_action_allowed(policy, "read")
        print({"is_allow": is_allow})
        if is_allow:
            print({"actions": actions})
    else:
        print("Policy not found.")

if __name__ == "__main__":
    asyncio.run(main())

Error Handling

  • Connection Errors: Handles network and server connectivity issues
  • Authentication Errors: Manages API key and authentication failures
  • Validation Errors: Validates input parameters and trust domains
  • Policy Errors: Handles policy retrieval and validation failures

License

MIT License

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

aztp_client-1.0.26.tar.gz (11.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

aztp_client-1.0.26-py3-none-any.whl (10.7 kB view details)

Uploaded Python 3

File details

Details for the file aztp_client-1.0.26.tar.gz.

File metadata

  • Download URL: aztp_client-1.0.26.tar.gz
  • Upload date:
  • Size: 11.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.2

File hashes

Hashes for aztp_client-1.0.26.tar.gz
Algorithm Hash digest
SHA256 49ddc1ceeb6292736b1e5c8e676c78271194c2f2f3c590977302a045713a8132
MD5 045241cd3ec3f8782cf08d644061818f
BLAKE2b-256 6d27dc60995b42694a986418f622852174f068e05524d72cee6ffbd425e588da

See more details on using hashes here.

File details

Details for the file aztp_client-1.0.26-py3-none-any.whl.

File metadata

  • Download URL: aztp_client-1.0.26-py3-none-any.whl
  • Upload date:
  • Size: 10.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.2

File hashes

Hashes for aztp_client-1.0.26-py3-none-any.whl
Algorithm Hash digest
SHA256 c0bd895e6249a0b27d336cdfb431b31ec348a9bc3a4773969635e9b3940405ca
MD5 f8ca5ad5730b9ef9ea1c2b264e39ae73
BLAKE2b-256 3e754fda2c721fe67dc2a6f66eb774f78ee728eebf3c1a0410f7d08f80810104

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page