Configuration API Reference¶
pycomptox.config
¶
Configuration management for PyCompTox.
This module handles API key storage and retrieval.
delete_api_key()
¶
Delete the saved API key from the configuration file.
Returns:
| Name | Type | Description |
|---|---|---|
bool |
bool
|
True if the key was deleted, False if it didn't exist. |
Example
from pycomptox.config import delete_api_key if delete_api_key(): ... print("API key deleted successfully!") ... else: ... print("No saved API key found.")
Source code in src/pycomptox/config.py
get_api_key_file()
¶
Get the path to the API key file.
Returns:
| Name | Type | Description |
|---|---|---|
Path |
Path
|
The API key file path. |
get_config_dir()
¶
Get the configuration directory for PyCompTox.
Returns:
| Name | Type | Description |
|---|---|---|
Path |
Path
|
The configuration directory path. |
The configuration directory is located at: - Windows: %APPDATA%\PyCompTox - macOS/Linux: ~/.pycomptox
Source code in src/pycomptox/config.py
get_config_info()
¶
Get information about the current configuration.
Returns:
| Name | Type | Description |
|---|---|---|
dict |
dict
|
Configuration information including paths and API key status. |
Example
from pycomptox.config import get_config_info info = get_config_info() print(f"Config directory: {info['config_dir']}") print(f"API key saved: {info['has_saved_key']}")
Source code in src/pycomptox/config.py
load_api_key()
¶
Load the API key from the configuration file.
Returns:
| Type | Description |
|---|---|
Optional[str]
|
Optional[str]: The API key if found, None otherwise. |
The function looks for the API key in the following order: 1. COMPTOX_API_KEY environment variable 2. Saved configuration file
Example
from pycomptox.config import load_api_key api_key = load_api_key() if api_key: ... print("API key loaded successfully!") ... else: ... print("No API key found. Please set one using save_api_key()")
Source code in src/pycomptox/config.py
save_api_key(api_key)
¶
Save the API key to the configuration file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
api_key
|
str
|
The CompTox Dashboard API key to save. |
required |
Example
from pycomptox.config import save_api_key save_api_key("your_api_key_here") print("API key saved successfully!")