Nestipy offers a module comparable to @nestjs/config, allowing you to load data from environment variables or a .env file, similar to the feature in NestJs.
Installation
To begin using it, we first install the required dependency.
bash
pip install nestipy_configTo simplify configuration, nestipy_config offer two methods to register the ConfigModule: for_root and for_root_async. Bellow is an example with for_root method.
python
from nestipy_config import ConfigModule, ConfigOption
from nestipy.common import Module
@Module(
imports=[
ConfigModule.for_root(ConfigOption(), is_global=True)
]
)
class AppModule:
...After that, we can inject ConfigService in any controller or any provider.
python
from typing import Annotated
from nestipy.common import Injectable
from nestipy.ioc import Inject
from nestipy_config import ConfigService
@Injectable()
class AppService:
config_service: Annotated[ConfigService, Inject()]Runtime Flags (Env)
Nestipy also supports lightweight runtime flags without the config module:
NESTIPY_DEBUG=1to enable debug behavior (0/false disables).NESTIPY_SECURITY_HEADERS=0to disable default security headers.NESTIPY_HEALTH=0to disable built-in/healthzand/readyz.NESTIPY_CORS_ALLOW_ALL=1to allow any origin.NESTIPY_CORS_ORIGINS=http://localhost:5173,https://example.comNESTIPY_CORS_ALLOW_METHODS=GET,POST,PUT,PATCH,DELETE,OPTIONSNESTIPY_CORS_ALLOW_HEADERS=Content-Type,Authorization,X-Request-IdNESTIPY_CORS_EXPOSE_HEADERS=X-Request-IdNESTIPY_CORS_ALLOW_CREDENTIALS=1NESTIPY_CORS_MAX_AGE=600NESTIPY_CORS_ORIGIN_REGEX=^https?://.*\.example\.com$
For actions security defaults, see Actions (RPC).
