Add Conduit Python client library

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
chelsea
2026-07-05 17:41:15 +00:00
parent 1d9e7e0fab
commit a3e6ef70df
8 changed files with 719 additions and 0 deletions

75
pythonlib/README.md Normal file
View File

@@ -0,0 +1,75 @@
# Conduit Python Client
Small synchronous Python client for the Conduit / Mega API gateway.
```python
from conduit import Client
client = Client.from_env()
print(client.health())
print(client.auth.me())
print(client.keys.list())
```
Configure it with environment variables:
```sh
export MEGA_API_BASE_URL=https://api.cowtunnel.com
export MEGA_API_KEY='mega_sk_live_...'
```
Do not put raw API keys in source files. Mega API keys are shown once by the
gateway and should live in environment variables, a secret manager, or a local
ignored config file.
## Common Calls
```python
from conduit import Client
client = Client(base_url="https://api.cowtunnel.com", api_key="...")
client.services.list()
client.sms.history(limit=1)
client.dns.server_status()
client.compute.resources(type="vm")
client.media.library.search(term="matrix", limit=5)
client.media.ingest.jobs()
```
Key management:
```python
created = client.keys.create(
display_name="automation",
scopes=["gateway:read", "sms:read"],
)
print(created["key"]) # shown only once
client.keys.revoke(created["key_prefix"])
```
Admin audit:
```python
client.admin.audit(scope="sms:send", result="denied")
```
## Errors
The library raises:
| Exception | Meaning |
|---|---|
| `MegaAPIConfigError` | Invalid/missing client configuration |
| `MegaAPIHTTPError` | Non-2xx response; includes `status_code`, `detail`, and `body` |
| `MegaAPIConnectionError` | Could not reach the gateway |
| `MegaAPIResponseError` | Gateway returned malformed JSON where JSON was expected |
## Naming
The import package is `conduit` for the private package registry. The public PyPI
name `conduit` is already used by an unrelated project, so publish publicly as
`conduit-client` if this ever leaves the private registry. `megaapi` remains as a
compatibility import alias.