Configuration#
bfabricPy can be configured through config files, environment variables, or code.
Configuration File (Recommended)#
Create a YAML file at ~/.bfabricpy.yml:
# ~/.bfabricpy.yml
GENERAL:
default_config: PRODUCTION # Default environment to use
PRODUCTION:
login: yourBfabricLogin
password: yourBfabricWebServicePassword # Get from B-Fabric profile
base_url: https://fgcz-bfabric.uzh.ch/bfabric/
TEST:
login: yourBfabricLogin
password: yourBfabricWebServicePassword
base_url: https://fgcz-bfabric-test.uzh.ch/bfabric/
Web Service Password#
The password in your config file is NOT your login password. Find your web service password:
Log into B-Fabric web interface
Go to your profile page
Find the “Web Service Password” section
Warning
This password authenticates you to the B-Fabric webservices. Make sure not to share it with others and ensure proper permissions for the configuration file.
Multiple Environments#
You can define multiple environments (e.g., PRODUCTION, TEST) and switch between them:
# Use default environment
python script.py
# Use TEST environment
BFABRICPY_CONFIG_ENV=TEST python script.py
Using Multiple Config Files#
Use a custom config file location:
from bfabric import Bfabric
from pathlib import Path
client = Bfabric.connect(
config_file_path=Path("/custom/path/config.yml"),
config_file_env="PRODUCTION",
)
Environment Variables#
bfabricPy supports several environment variables for configuration.
BFABRICPY_CONFIG_ENV#
Sets the default environment to use:
export BFABRICPY_CONFIG_ENV=TEST
python script.py # Will use TEST environment
BFABRICPY_CONFIG_OVERRIDE#
Complete configuration override (highest priority). Used primarily for integration tests, where it needs to be prevented that the regular config file leads to the wrong B-Fabric instance being modified.
export BFABRICPY_CONFIG_OVERRIDE='{"client": {"base_url": "https://fgcz-bfabric.uzh.ch/bfabric/"}, "auth": {"login": "myuser", "password": "mypass"}}'
python script.py # Uses this config, ignoring ~/.bfabricpy.yml
Priority Order {#priority-order}#
Configuration is loaded in this order (highest to lowest):
BFABRICPY_CONFIG_OVERRIDE - Complete config override
config_file_env parameter in code
BFABRICPY_CONFIG_ENV environment variable
default_config in config file
Code-Based Configuration#
For maximum flexibility, you can provide configuration in code:
from bfabric import Bfabric
from bfabric.config import BfabricAuth, BfabricClientConfig
# Create config programmatically
client_config = BfabricClientConfig(
base_url="https://fgcz-bfabric.uzh.ch/bfabric/",
engine="zeep", # or "suds"
)
auth = BfabricAuth(
login="your_login",
password="your_password",
)
# Note: This is for advanced use cases. See API Reference for details.
Token-Based Configuration (Web Apps)#
For web applications that receive B-Fabric tokens, see:
Best Practices#
Never commit config files to git - Use environment variables for CI/CD
Use TEST environment for development and testing
Separate credentials - Different users for different projects/environments
Document your environments - Comment in config files to explain each environment’s purpose
Use environment variables for secrets in containerized deployments
See Also#
Installation Guide - Installation options
Creating a Client Guide - How to use configuration
Server/Webapp Configuration - Token-based auth
Troubleshooting - Common issues and solutions