Configuration#

bfabricPy can be configured through config files, environment variables, or code.

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):

  1. BFABRICPY_CONFIG_OVERRIDE - Complete config override

  2. config_file_env parameter in code

  3. BFABRICPY_CONFIG_ENV environment variable

  4. 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#

  1. Never commit config files to git - Use environment variables for CI/CD

  2. Use TEST environment for development and testing

  3. Separate credentials - Different users for different projects/environments

  4. Document your environments - Comment in config files to explain each environment’s purpose

  5. Use environment variables for secrets in containerized deployments

See Also#