cfenv
raw JSON → 0.5.3 verified Mon Apr 27 auth: no python
Python wrapper for Cloud Foundry environments, providing easy access to VCAP_SERVICES and VCAP_APPLICATION environment variables. Current version: 0.5.3, updates infrequent.
pip install cfenv Common errors
error AttributeError: 'CfEnv' object has no attribute 'name' ↓
cause Usually missing or malformed VCAP_APPLICATION environment variable.
fix
Ensure you are running inside Cloud Foundry or set VCAP_APPLICATION manually for testing.
error ImportError: No module named cfenv ↓
cause Library not installed.
fix
Run: pip install cfenv
Warnings
gotcha CfEnv() expects VCAP_APPLICATION to be set; throws AttributeError if not in a Cloud Foundry environment. ↓
fix Wrap in try-except or check the environment first.
gotcha Accessing service credentials via cfenv.get_credential() may return None if key missing. ↓
fix Use .get() with default or check key existence.
deprecated Methods like .get_service() may be renamed; prefer .get_service(name=...) over positional args. ↓
fix Use keyword arguments: cfenv.get_service(name='my-service')
Imports
- CfApp
from cfenv import CfApp - CfEnv
from cfenv import CfEnv
Quickstart
from cfenv import CfEnv
cfenv = CfEnv()
print('App name:', cfenv.name)
print('URI:', cfenv.uri)
print('Port:', cfenv.port)