Documentation Index
Fetch the complete documentation index at: https://mintlify.com/aveni-hub/avenieca-python/llms.txt
Use this file to discover all available pages before exploring further.
The AveniECA API supports two authentication methods: username/password and API token.
Config Class
The Config dataclass holds all configuration parameters:
from avenieca.api.model import Config
config = Config(
api_token="", # Optional: Direct API token
username="", # Optional: Username for login
password="", # Optional: Password for login
uri="" # Required: API base URL
)
Parameters
uri (str) - Base URL of the ECA API (e.g., http://localhost:2580/v1)
api_token (str, optional) - Pre-existing session token
username (str, optional) - Username for authentication
password (str, optional) - Password for authentication
Authentication Methods
Username and Password
When you initialize the ECA class with username and password, it automatically performs a login to retrieve an API token:
import os
from avenieca.api.eca import ECA
from avenieca.api.model import Config
config = Config(
uri="http://localhost:2580/v1",
username=os.getenv("USERNAME"),
password=os.getenv("PASSWORD")
)
# Login happens automatically during initialization
eca = ECA(config)
API Token
If you already have a session token, you can provide it directly:
from avenieca.api.eca import ECA
from avenieca.api.model import Config
config = Config(
uri="http://localhost:2580/v1",
api_token="your-session-token-here"
)
eca = ECA(config)
Authentication Flow
The ECA class handles authentication automatically:
- If
api_token is provided and not empty, it uses the token directly
- If
api_token is empty, it performs a login using username and password
- The retrieved session token is stored in
config.api_token
- All subsequent API calls use this token
From avenieca/api/eca.py:14-21:
if config.api_token == "":
self.auth = auth.Auth(config)
auth_login = AuthLogin(username=config.username, password=config.password)
response, status = self.auth.login(auth_login)
if status != requests.codes['ok']:
raise Exception("login failed: %s", response)
response: AuthResponse = response
config.api_token = response.session_id
AuthResponse Model
Successful login returns an AuthResponse object:
@dataclass
class AuthResponse(Base):
role: str # User role
session_id: str # Session token for API calls
user_id: str # User identifier
username: str # Username
Example with Environment Variables
import os
from avenieca.api.eca import ECA
from avenieca.api.model import Config
# Load credentials from environment
username = os.getenv("USERNAME")
password = os.getenv("PASSWORD")
config = Config(
uri="http://localhost:2580/v1",
username=username,
password=password
)
try:
eca = ECA(config)
print("Authentication successful")
except Exception as e:
print(f"Authentication failed: {e}")
Security Best Practices
- Store credentials in environment variables, not in code
- Use API tokens when possible to avoid repeated logins
- Rotate tokens regularly
- Never commit credentials to version control