quart icon indicating copy to clipboard operation
quart copied to clipboard

Hypercorn Does Not Load Environment Variables From Session

Open cfloressuazo opened this issue 8 months ago • 0 comments

Issue Description When running Hypercorn directly from the command line, it does not properly access environment variables set in the current shell session. This causes applications to default to fallback values instead of using the configured environment variables.

Steps to Reproduce

  • Set environment variables in shell:
    export REDIS_HOST="my-redis-server"
    export REDIS_PORT="6379"
    
  • Run application with Hypercorn:
    hypercorn main:app
    
  • Observe application logs showing default values instead of environment variables:
    *********************************************
    REDIS_HOST: localhost
    REDIS_PORT: 6380
    REDIS_PASS: None
    REDIS_USE_SSL: False
    REDIS_POOL_SIZE: 10
    *********************************************
    

Expected Behavior Hypercorn should load and make available all environment variables from the parent shell session, allowing the application to access them via os.environ or os.getenv().

Actual Behavior Environment variables set in the shell session are not accessible to the application when started with Hypercorn directly.

Workarounds

  1. Set environment variables inline with the Hypercorn command:
  2. Use python-dotenv in your application to load variables from a .env file
  3. In Docker deployments, explicitly pass environment variables through the container

Environment:

  • Python version: 3.11
  • Quart version: 0.20.0
  • Hypercorn: 0.17.3

cfloressuazo avatar Apr 04 '25 14:04 cfloressuazo