Complete the code to load environment variables using Pydantic BaseSettings.
from pydantic import BaseSettings class Settings(BaseSettings): app_name: str settings = Settings() print(settings.[1])
The app_name attribute is accessed from the settings instance to get the environment variable value.
Complete the code to specify a custom environment file for Pydantic BaseSettings.
from pydantic import BaseSettings class Settings(BaseSettings): debug: bool class Config: env_file = [1] settings = Settings() print(settings.debug)
The env_file attribute in the Config class tells Pydantic to load environment variables from a file named .env.
Fix the error in the code to correctly read an integer environment variable.
from pydantic import BaseSettings class Settings(BaseSettings): port: int settings = Settings() print(settings.[1])
The attribute name port must match the class attribute to access the integer environment variable correctly.
Fill both blanks to create a Pydantic Settings class that reads a string and a boolean from environment variables.
from pydantic import BaseSettings class Settings(BaseSettings): [1]: str [2]: bool settings = Settings() print(settings.api_key, settings.debug_mode)
The class defines api_key as a string and debug_mode as a boolean to read those environment variables.
Fill all three blanks to create a Settings class that reads a host string, a port integer, and a debug boolean from environment variables.
from pydantic import BaseSettings class Settings(BaseSettings): [1]: str [2]: int [3]: bool settings = Settings() print(settings.host, settings.port, settings.debug)
The class attributes host, port, and debug correspond to environment variables for host, port, and debug mode.