Config Module
Configuration module for Record Shelf
- class record_shelf.config.Config(token=None, user_agent='RecordShelf/1.0', debug=False, rate_limit_delay=1.0)[source]
Bases:
objectApplication configuration
-
user_agent:
str= 'RecordShelf/1.0'
-
debug:
bool= False
-
rate_limit_delay:
float= 1.0
- property discogs_headers: dict
Headers for Discogs API requests
-
user_agent:
Configuration Management
The Config module handles application configuration, including API tokens, user agents, and rate limiting settings.
Usage Examples
Basic Configuration
from record_shelf.config import Config
# Basic configuration with token
config = Config(token="your_discogs_token")
# Configuration with environment variable
import os
os.environ['DISCOGS_TOKEN'] = 'your_token'
config = Config() # Will use environment variable
Advanced Configuration
from record_shelf.config import Config
# Custom configuration
config = Config(
token="your_token",
user_agent="MyCustomApp/2.0",
rate_limit_delay=2.0, # 2 second delay between requests
debug=True
)
# Access configuration properties
print(f"User Agent: {config.user_agent}")
print(f"Rate Limit: {config.rate_limit_delay}")
print(f"Headers: {config.discogs_headers}")
Error Handling
from record_shelf.config import Config
try:
# This will raise ValueError if no token is found
config = Config()
except ValueError as e:
print(f"Configuration error: {e}")
# Handle missing token
Configuration Options
Parameter |
Type |
Description |
|---|---|---|
|
|
Discogs API token. If None, will try to get from DISCOGS_TOKEN environment variable. |
|
|
User agent string for API requests. Default: “RecordShelf/1.0” |
|
|
Enable debug mode. Default: False |
|
|
Delay in seconds between API calls. Default: 1.0 |
Environment Variables
Variable |
Description |
|---|---|
|
Discogs API token. Used if no token is provided to Config constructor. |
Best Practices
Token Security
Store tokens in environment variables, not in code
Use different tokens for development and production
Rotate tokens regularly
Never commit tokens to version control
Rate Limiting
Default 1 second delay is conservative and safe
Increase delay for large collections or slow networks
Decrease delay only if you’re sure about API limits
Monitor for rate limit errors in logs
Debugging
Enable debug mode for troubleshooting
Check logs for detailed API interaction information
Use debug mode to understand rate limiting behavior