What Is the Purpose of the config.py File in AI Berkshire?
The AI Berkshire repository intentionally omits a config.py file, relying instead on environment variables for sensitive credentials and hard-coded constants within individual modules for static configuration values.
The xbtlin/ai-berkshire project follows a decentralized configuration pattern that prioritizes security and minimal coupling. Rather than centralizing settings in a single config.py module, the codebase distributes configuration across environment variables and inline constants. This approach keeps secrets out of version control while allowing each tool to define only the parameters it requires, as implemented in utilities like tools/financial_rigor.py and tools/morningstar_fair_value.py.
Why AI Berkshire Omits a Central config.py
The repository adheres to the principle of never committing secrets to source control. A monolithic config.py would risk accidental exposure of API keys and service endpoints. Instead, the project reads sensitive values at runtime using os.getenv, ensuring that credentials remain in local .env files excluded from Git via .gitignore.
Environment Variables for Secrets
Sensitive configuration values such as API keys and external service endpoints are loaded from the environment. The tools/morningstar_fair_value.py module demonstrates this pattern by reading the Morningstar API key at startup and raising a clear error if it is missing.
# tools/morningstar_fair_value.py
import os
from pathlib import Path
# The API key is expected to be defined in .env
MORNINGSTAR_API_KEY = os.getenv("MORNINGSTAR_API_KEY")
if not MORNINGSTAR_API_KEY:
raise RuntimeError("Missing MORNINGSTAR_API_KEY – set it in .env")
# Use the key to build request headers
HEADERS = {"Authorization": f"Bearer {MORNINGSTAR_API_KEY}"}
Inline Constants for Static Values
For non-sensitive, stable parameters such as default file paths, CSV column names, and quantitative thresholds, the code defines simple Python constants at the top of the relevant module. Files like tools/financial_rigor.py and tools/stock_screener.py implement this approach, keeping configuration co-located with the logic that consumes it. Similarly, scripts/sync-codex-skills.py handles its settings via command-line arguments rather than importing from a central configuration file.
How to Implement a Configuration Helper
If your workflow requires a centralized configuration module, you can create a lightweight helper that reads environment variables without modifying the core repository structure. This pattern maintains the security benefits of the .env approach while reducing duplication across multiple tools.
# config_example.py (optional helper – not part of the repo yet)
from pathlib import Path
from dotenv import load_dotenv
import os
# Load .env from the repository root
env_path = Path(__file__).resolve().parent.parent / ".env"
load_dotenv(dotenv_path=env_path)
# Example configuration values
XUEQIU_API_KEY = os.getenv("XUEQIU_API_KEY")
MORNINGSTAR_ENDPOINT = os.getenv("MORNINGSTAR_ENDPOINT", "https://api.morningstar.com")
DEFAULT_DATA_DIR = Path(os.getenv("DATA_DIR", "./data"))
You can then import this helper in new scripts while preserving the repository’s security model:
# my_feature.py
from config_example import DEFAULT_DATA_DIR, XUEQIU_API_KEY
def fetch_data():
# Use the shared data directory and API key
cache_path = DEFAULT_DATA_DIR / "xueqiu_cache.json"
# …rest of the logic…
Summary
- The AI Berkshire repository does not contain a
config.pyfile by design. - Environment variables (typically from a
.envfile) handle sensitive credentials like API keys, as implemented intools/morningstar_fair_value.py. - Hard-coded constants within modules manage static configuration such as thresholds and paths, visible in
tools/financial_rigor.pyandtools/stock_screener.py. - This pattern prevents accidental credential leakage and supports environment-specific deployments without code changes.
Frequently Asked Questions
Does AI Berkshire use a config.py file?
No. According to the xbtlin/ai-berkshire source code, the repository intentionally avoids a central config.py. The project uses environment variables for secrets and inline constants for static values, eliminating the risk of committing sensitive data to version control.
How do I add API keys to AI Berkshire?
Create a .env file in the repository root and add your keys there (e.g., MORNINGSTAR_API_KEY=your_key_here). The codebase uses os.getenv() to read these values at runtime, as demonstrated in tools/morningstar_fair_value.py. Ensure .env is listed in your .gitignore to prevent accidental commits.
Where are default thresholds and paths defined?
Default thresholds, file paths, and other static parameters are defined as Python constants within the specific modules that consume them. For example, tools/financial_rigor.py contains valuation thresholds, while tools/stock_screener.py defines screening criteria constants directly in the source file.
Is it safe to create a config.py file for my fork?
While you can create a helper module for convenience, avoid hard-coding secrets into it. If you implement a config.py in your fork, ensure it only reads from environment variables (like the optional config_example.py pattern shown above) rather than storing literal API keys, maintaining the repository's security posture.
Have a question about this repo?
These articles cover the highlights, but your codebase questions are specific. Give your agent direct access to the source. Share this with your agent to get started:
curl -s "https://instagit.com/install.md" Maintain an open-source project? Get it listed too →