Python client for the AFA API -- autonomous code evolution with 9 quantitative gates
Project description
AFA Client SDK
Python client for the AFA REST API: autonomous code evolution with 9 quantitative gates.
pip install afa-client
Quick start
from afa_client import AFA
client = AFA(api_key="uk_afa_...")
# Analyze code
result = client.analyze(code="def hello(name):\n print('Hello ' + name)")
for r in result.results:
print(r["scores"])
for finding in r["findings"]:
print(f" [{finding['severity']}] {finding['message']}")
# Generate and gate-check an enhancement
enhanced = client.enhance(
code="def hello(name):\n print('Hello ' + name)",
dry_run=True,
)
print(enhanced.status) # "pass" if all 9 gates passed
Async
from afa_client import AsyncAFA
async with AsyncAFA(api_key="uk_afa_...") as client:
result = await client.analyze(code="def foo(): pass")
Authentication
Pass your API key directly or set it as an environment variable:
export AFA_API_KEY="uk_afa_..."
Get your key at portal.veiltide.com.
Methods
| Method | Description |
|---|---|
analyze(code, language, depth) |
Analyze code with 4 AI agents |
enhance(code, language, dry_run) |
Generate enhancement + run 9 gates |
gate_check(metrics) |
Evaluate raw metrics against gates |
health() |
API health check (no auth) |
history(last) |
Query audit trail |
metrics() |
Prometheus metrics |
get_profile() |
Customer profile + tier |
get_usage(month) |
Monthly usage report |
list_keys() |
List API keys |
create_key(name) |
Create new API key |
revoke_key(key_id) |
Revoke an API key |
Error handling
from afa_client import AFA, RateLimitError, AuthenticationError
client = AFA()
try:
result = client.analyze(code="def foo(): pass")
except RateLimitError as e:
print(f"Rate limited. Retry after {e.retry_after}s")
except AuthenticationError:
print("Invalid API key")
Configuration
| Parameter | Env var | Default |
|---|---|---|
api_key |
AFA_API_KEY |
Required |
base_url |
AFA_BASE_URL |
https://api.afa.undercurrentholdings.com |
timeout |
-- | 30s |
max_retries |
-- | 2 |
Security
- TLS enforced on all non-localhost connections
- API key transmitted only in
Authorization: Bearerheader - Key masking in all error messages and repr output
- Automatic retry with exponential backoff + jitter
- Idempotency keys on mutating requests
- HTTP/2 enabled by default
License
Apache 2.0
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
afa_client-0.2.0.tar.gz
(18.4 kB
view details)
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file afa_client-0.2.0.tar.gz.
File metadata
- Download URL: afa_client-0.2.0.tar.gz
- Upload date:
- Size: 18.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.11
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d6893c0e6a7a894d986a358447e8625eb3eb5b0187b70623ce90bdc85143d295
|
|
| MD5 |
2a36c1125ab7fb98eb6f10f9c3a7671e
|
|
| BLAKE2b-256 |
a391b3ab94f3a9696ad4053d70cb0fea6717b7b94529f424c12fc5ee10600b85
|
File details
Details for the file afa_client-0.2.0-py3-none-any.whl.
File metadata
- Download URL: afa_client-0.2.0-py3-none-any.whl
- Upload date:
- Size: 18.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.11
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4e6e60597bbe3027030e7b7d93ab908cba286d10405a7cb83eabe8ad42a3280f
|
|
| MD5 |
75e6bbba1f4ba2464951fa8decefc4bc
|
|
| BLAKE2b-256 |
f3e56a3d16000bdbf319d9e1f0bc4e0c7122ab51b91061d98111103091959e3b
|