|
3 | 3 | This is a Python library for interacting with the Athena API (Resolver Unknown |
4 | 4 | CSAM Detection). |
5 | 5 |
|
| 6 | +## Authentication |
| 7 | + |
| 8 | +The Athena client supports two authentication methods: |
| 9 | + |
| 10 | +### Static Token Authentication |
| 11 | +```python |
| 12 | +from athena_client.client.channel import create_channel |
| 13 | + |
| 14 | +# Use a pre-existing authentication token |
| 15 | +channel = create_channel(host="your-host", auth_token="your-token") |
| 16 | +``` |
| 17 | + |
| 18 | +### OAuth Credential Helper (Recommended) |
| 19 | +The credential helper automatically handles OAuth token acquisition and refresh: |
| 20 | + |
| 21 | +```python |
| 22 | +import asyncio |
| 23 | +from athena_client.client.channel import CredentialHelper, create_channel_with_credentials |
| 24 | + |
| 25 | +async def main(): |
| 26 | + # Create credential helper with OAuth settings |
| 27 | + credential_helper = CredentialHelper( |
| 28 | + client_id="your-oauth-client-id", |
| 29 | + client_secret="your-oauth-client-secret", |
| 30 | + auth_url="https://crispthinking.auth0.com/oauth/token", # Optional, this is default |
| 31 | + audience="crisp-athena-dev" # Optional, this is default |
| 32 | + ) |
| 33 | + |
| 34 | + # Create channel with automatic OAuth handling |
| 35 | + channel = await create_channel_with_credentials( |
| 36 | + host="your-host", |
| 37 | + credential_helper=credential_helper |
| 38 | + ) |
| 39 | + |
| 40 | +asyncio.run(main()) |
| 41 | +``` |
| 42 | + |
| 43 | +#### Environment Variables |
| 44 | +For the OAuth example to work, set these environment variables: |
| 45 | +```bash |
| 46 | +export OAUTH_CLIENT_ID="your-client-id" |
| 47 | +export OAUTH_CLIENT_SECRET="your-client-secret" |
| 48 | +export ATHENA_HOST="your-athena-host" |
| 49 | +``` |
| 50 | + |
| 51 | +#### OAuth Features |
| 52 | +- **Automatic token refresh**: Tokens are automatically refreshed when they expire |
| 53 | +- **Thread-safe**: Multiple concurrent requests will safely share cached tokens |
| 54 | +- **Error handling**: Comprehensive error handling for OAuth failures |
| 55 | +- **Configurable**: Custom OAuth endpoints and audiences supported |
| 56 | + |
| 57 | +See `examples/oauth_example.py` for a complete working example. |
| 58 | + |
| 59 | +## Examples |
| 60 | + |
| 61 | +- `examples/example.py` - Basic classification example with static token |
| 62 | +- `examples/oauth_example.py` - OAuth authentication with credential helper |
| 63 | +- `examples/create_image.py` - Image generation utilities |
| 64 | + |
| 65 | +## TODO |
| 66 | + |
| 67 | +### Async pipelines |
| 68 | +Make pipeline style invocation of the async interators such that we can |
| 69 | + |
| 70 | +async read file -> async transform -> async classify -> async results |
| 71 | + |
| 72 | +### More async pipeline transformers |
| 73 | +Add additional pipeline transformers for: |
| 74 | +- Image format conversion |
| 75 | +- Metadata extraction |
| 76 | +- Error recovery and retry |
| 77 | + |
| 78 | + |
6 | 79 |
|
7 | 80 | ## Development |
8 | 81 | This package uses [uv](https://docs.astral.sh/uv/) to manage its packages. |
|
0 commit comments