.env相关配置案例 .env相关配置案例#!/usr/bin/env python# -*- coding: utf-8 -*- Time : 2025/5/14 10:44 Author : thezehuigmail.com File : config.py fromfunctoolsimportlru_cachefromtypingimportOptionalfrompydantic_settingsimportBaseSettings,SettingsConfigDictclassSettings(BaseSettings):MoocManus后端中控配置信息从.env或者环境变量中加载数据# 项目基础配置env:strdevelopmentlog_level:strINFO# 日志等级app_config_filepath:strconfig.yaml# 数据库相关配置sqlalchemy_database_uri:strpostgresqlasyncpg://postgres:postgreslocalhost:5432/manus# Redis缓存配置redis_host:strlocalhostredis_port:int6379redis_db:int0redis_password:str|NoneNone# Cos腾讯云对象存储配置cos_secret_id:strcos_secret_key:strcos_region:strcos_scheme:strhttpscos_bucket:strcos_domain:str# Sandbox配置sandbox_address:Optional[str]Nonesandbox_image:Optional[str]Nonesandbox_name_prefix:Optional[str]Nonesandbox_ttl_minutes:Optional[int]60sandbox_network:Optional[str]Nonesandbox_chrome_args:Optional[str]sandbox_https_proxy:Optional[str]Nonesandbox_http_proxy:Optional[str]Nonesandbox_no_proxy:Optional[str]None# 使用pydantic v2的写法来完成环境变量信息的告知model_configSettingsConfigDict(env_file.env,env_file_encodingutf-8,extraignore,)lru_cache()defget_settings()-Settings:获取当前MoocManus项目的配置信息并对内容进行缓存避免重复读取settingsSettings()returnsettingsif__name____main__:sttingsSettings()print(sttings)