Setup & Configuration¶
This guide will walk you through setting up your LLM API credentials and configuring faker-news.
Interactive Setup (Recommended)¶
The easiest way to configure faker-news is using the interactive setup wizard:
This wizard will:
- โ Check if you already have API keys configured (in keyring or environment)
- ๐ Guide you through selecting and configuring an LLM provider
- ๐พ Securely store your API key in your system's credential manager
- ๐งช Test the connection with a sample generation
- โจ Confirm everything is working
Secure API Key Storage¶
faker-news uses Python's keyring library to store API keys securely in your system's native credential manager:
| Platform | Storage Location |
|---|---|
| macOS | Keychain |
| Windows | Credential Manager |
| Linux | Secret Service (GNOME Keyring/KWallet) |
This is more secure than environment variables or config files, as the credentials are encrypted and managed by your OS.
Manual Configuration¶
If you prefer to configure manually, you have three options:
Option 1: System Keyring (Secure)¶
Set your API key in the system keyring using Python:
import keyring
# For OpenAI
keyring.set_password("faker-news", "openai", "sk-your-api-key-here")
# For Alibaba DashScope/Qwen
keyring.set_password("faker-news", "dashscope", "sk-your-api-key-here")
Option 2: Environment Variables¶
Set environment variables (less secure, but useful for CI/CD):
Option 3: Programmatic Configuration¶
Pass credentials directly in your code:
from faker import Faker
from faker_news import NewsProvider, LLMClientConfig
# Configure LLM client
llm_config = LLMClientConfig(
api_key="sk-your-api-key-here",
base_url="https://api.openai.com/v1", # Optional
model_headlines="gpt-4o-mini", # Optional
model_writing="gpt-4o-mini" # Optional
)
# Create provider with config
fake = Faker()
provider = NewsProvider(fake, llm_config=llm_config)
fake.add_provider(provider)
API Key Lookup Order¶
faker-news searches for API keys in this order:
- System keyring (checked first via
keyring.get_password()) - Environment variables (
OPENAI_API_KEYorDASHSCOPE_API_KEY) - Explicit config (passed to
LLMClientConfig)
This allows you to use the secure keyring for local development while using environment variables in CI/CD pipelines.
Testing Your Configuration¶
After configuring your API key, test it:
Using the CLI¶
# The setup wizard includes a test
faker-news setup
# Or manually test by generating a headline
faker-news headline
Using Python¶
from faker import Faker
from faker_news import NewsProvider
fake = Faker()
fake.add_provider(NewsProvider(fake))
# This will fail if credentials are not configured
try:
headline = fake.news_headline()
print(f"โ
Success! Generated: {headline}")
except Exception as e:
print(f"โ Error: {e}")
Database Location¶
By default, faker-news stores the cache in platform-specific directories:
| Platform | Cache Location |
|---|---|
| Linux | ~/.cache/faker-news/cache.sqlite3 |
| macOS | ~/Library/Caches/faker-news/cache.sqlite3 |
| Windows | %LOCALAPPDATA%\faker-news\cache\cache.sqlite3 |
Using a Custom Database Location¶
You can override the default location:
Via Python:
Via CLI:
Troubleshooting¶
API Key Not Found¶
If you get "API key not configured" errors:
- Run
faker-news setupto check your configuration - Verify environment variables:
echo $OPENAI_API_KEY - Check keyring: Run the Python snippet above to view stored keys
Connection Errors¶
If you get connection errors:
- Verify your API key is correct
- Check your internet connection
- Verify the
base_urlis correct for your provider - Check if your LLM provider is experiencing downtime
Keyring Issues on Linux¶
If keyring doesn't work on Linux, you may need to install a secret service backend:
Or use environment variables as a fallback.
Next Steps¶
- Quick Start - Start generating content
- LLM Providers - Detailed guides for specific LLM providers
- Configuration - Customize models, batch sizes, and more