
Security News
Opengrep Adds Apex Support and New Rule Controls in Latest Updates
The latest Opengrep releases add Apex scanning, precision rule tuning, and performance gains for open source static code analysis.
Get and cast environment variables
python setup.py install
Call from_env()
with the name of an environment variable, and either a default
value to return if the environment variable is not set, or a type to cast the
environment variable's value to if it is set. If a default value is passed and the
variable is set, its value will be cast to the type of the default value.
Actually, any callable can be passed as the second parameter, and will be used to
cast the value if it's not None. So if you pass e.g. json.loads
a JSON env var value
will be cast to a Python list
or dict
.
Also, if the type of the default value – or the type passed in instead – is bool
,
from_env()
will return True
if the environment variable's string value is any
of '1'
, 'true'
, 't'
, 'yes'
, 'y'
, and 'on'
, and False
otherwise.
from cast_from_env import from_env
from json import loads
from_env('STRING_VAR', 'default value') # Value or 'default value' if not set
from_env('INTEGER_VAR', 100) # Value cast to int, or 100 if not set
from_env('INTEGER_VAR', int) # Value cast to int, or None if not set
from_env('FLOAT_VAR', 1.0) # Value cast to float, or 1.0 if not set
from_env('TRUE_VAR', bool) # True if value is '1', 'true', 'yes', or 'on'
from_env('TRUE_VAR', True) # True if value is '1', 'true', 'yes', 'on', or not set
from_env('TEST_JSON', loads) # JSON string is cast to Python list or dict
FAQs
Get and cast environment variables
We found that cast-from-env demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
The latest Opengrep releases add Apex scanning, precision rule tuning, and performance gains for open source static code analysis.
Security News
npm now supports Trusted Publishing with OIDC, enabling secure package publishing directly from CI/CD workflows without relying on long-lived tokens.
Research
/Security News
A RubyGems malware campaign used 60 malicious packages posing as automation tools to steal credentials from social media and marketing tool users.