pyakta
Python library for Akta.
Akta is a system designed to enable secure and verifiable interactions between AI agents. It establishes a robust framework for capability-based access control, allowing agents to confidently delegate tasks and share resources with fine-grained control. The system leverages concepts from Decentralized Identifiers (DIDs) and Verifiable Credentials (VCs) to create a cryptographically secure and auditable environment for autonomous agent operations.
Important Note: Akta is currently a prototype. The codebase has not undergone a third-party security audit and is not yet considered suitable for production environments. Development will move fast, expect breaking changes, bugs, and other issues.
Features
- Capability-based access control using Verifiable Credentials.
- Generation and management of Decentralized Identifiers (
did:keyanddid:webmethods). - Creation, signing, and verification of W3C Verifiable Credentials using Ed25519Signature2020.
- Pydantic models for core data structures (VCs, DIDs, Proofs).
- Cryptographically secure operations leveraging PyNaCl.
- JSON-LD processing for credential normalization.
Requirements
- Python 3.11+
base58>=2.1.1pynacl>=1.5.0pydantic>=2.11.0pyld>=2.0.4
Installation
You can install pyakta in a few ways:
From PyPI:
pip install pyakta
From Source:
git clone https://github.com/lukehinds/pyakta.git
cd pyakta
Usage
Here's a basic example of how to generate a DID and create/sign a Verifiable Credential:
from pyakta.did import DIDKey
from pyakta.credentials import VerifiableCredential
from datetime import datetime, timedelta, UTC # Make sure UTC is imported
# 1. Generate an issuer DID (did:key method)
issuer_did_key = DIDKey()
print(f"Issuer DID: {issuer_did_key.did}")
print(f"Issuer Public Key (Multibase): {issuer_did_key.public_key_multibase}")
# 2. Define subject and credential details
subject_did_str = "did:example:subject123"
now = datetime.now(UTC)
# 3. Build the Verifiable Credential
vc = VerifiableCredential().build(
issuer_did=issuer_did_key.did,
subject_did=subject_did_str,
types=["VerifiableCredential", "AgentAccessCredential"],
issuance_date=now,
expiration_date=now + timedelta(days=30),
credential_subject={
"id": subject_did_str,
"serviceEndpoint": "https://example.com/agent/service",
"actions": ["read", "write"]
}
)
# 4. Sign the Verifiable Credential
# The verification method ID for did:key is typically the DID itself + # + public key multibase
verification_method = f"{issuer_did_key.did}#{issuer_did_key.public_key_multibase}"
vc.sign(
issuer_signing_key=issuer_did_key.signing_key,
verification_method_id=verification_method
)
print("\nSigned Verifiable Credential:")
print(vc.to_json(indent=2))
# 5. Verify the Verifiable Credential
is_valid = vc.verify_signature(
issuer_public_key=issuer_did_key.verify_key,
expected_issuer_did=issuer_did_key.did,
expected_subject_did=subject_did_str
)
print(f"\nVC Signature Valid: {is_valid}")
# Check expiration
print(f"VC Expired: {vc.is_expired()}")
This example demonstrates:
- Generating a
did:key. - Building a
VerifiableCredentialwith specific subject data, type, issuance, and expiration. - Signing the credential using the issuer's signing key.
- Verifying the credential's signature.
Running Tests
Tests are managed using pytest. To run the tests:
- Ensure you have the development dependencies installed:
pip install -e ".[dev]" # or if using PDM: # pdm install -G dev
- Navigate to the root of the project and run:
pytest
Or, if you have aMakefilewith a test target (as indicated by your test output):make test
This will discover and run all tests in the pyakta/tests directory and provide a coverage report.
Contributing
We honestly love getting contributions, from engineers of all levels and background!
Don't be put off contributing, we're all learning as we go and everyone starts somewhere.
You could always look for good first issues to get started, and tag me in the PR (@lukehinds) and I am happy to give you plently of friendly support and guidance (if you want it).
License
This project is licensed under the Apache 2.0 License - see the LICENSE file for details.
Metadata
Release files for pyakta 0.5.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| pyakta-0.5.0.tar.gz | 25.2 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| pyakta-0.5.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 42.5 kB
Release files / pyakta-0.5.0.tar.gz
| Download URL | pyakta-0.5.0.tar.gz |
|---|---|
| Size | 25.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
7bff358f6ecc1f05aa96e221cd61afac0a8b3c7e209e4987200fd1a492e4d662
|
|
BLAKE2b-256 checksum How to use checksums |
9a1e43c9d77278b9f49f6182cc5d3edf44538edd6a9c796555c8ca9995ca2a90
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.12.9
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Jun 5, 2025.
Transparency logRelease files / pyakta-0.5.0-py3-none-any.whl
| Download URL | pyakta-0.5.0-py3-none-any.whl |
|---|---|
| Size | 17.3 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
9827a56d0f0f11b3eac40b0f4a53bf77527b856664e44676e9943f05c425bb38
|
|
BLAKE2b-256 checksum How to use checksums |
1488e83755b94cb5416b50e2515ae90328abab4b4a080d12e6245cd5e433f87c
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.12.9
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Jun 5, 2025.
Transparency log