
Product
Introducing Scala and Kotlin Support in Socket
Socket now supports Scala and Kotlin, bringing AI-powered threat detection to JVM projects with easy manifest generation and fast, accurate scans.
Custom tags to extend YAML for managing advanced configurations easily within a file. Environment variables, includes, and jinja templating.
Provides a set of custom tags to extend YAML for managing advanced configurations easily within a file. It supports:
!env
!include
!jinja
pip install yaml-config-tags
Simply load the configuration file using config_load
and pass a context dictionary to the loader.
config_load(
path: str | Path,
context: dict[str, Any] | None = None,
jinja_settings: dict[str, Any] | None = None,
jinja_filters: dict[str, Callable] | None = None,
) -> Any
from yaml_config import config_load
context = {
'name': 'John Doe'
}
config = config_load('config.yml', context)
# config.yml
database:
user: !env DB_USER
password: !env DB_PASSWORD
advanced: !include advanced.yaml
greeting: !jinja |
Hello, {{ name }}!
You can use environment variables in your configuration file by using the !env
tag.
There are three ways to use environment variables:
!env VAR_NAME
- Load the environment variable VAR_NAME
. If it is not set, an exception will be raised.!env [VAR_NAME, default_value]
- Load the environment variable VAR_NAME
with a default value if it is not set.!env [VAR_NAME, FALLBACK_VAR1, .., FALLBACK_VARn, default_value]
- Load the environment variable VAR_NAME
, if it is not set, try to load the fallback variables in order. If none of them are set, use the default value.Environment variables are converted using implicit yaml types by default, but you can force a specific data type with tag suffix:
!env:str VAR_NAME
!env:int VAR_NAME
Valid type suffix are:
You can also combine defaults and fallbacks with type suffix:
!env:str [VAR_NAME, default_value]
You can include other files in your configuration file by using the !include
tag.
# config.yml
advanced: !include advanced.yaml
Three types of files are supported, specified as a tag suffix:
yaml
- Load the file as a YAML file.json
- Load the file as a JSON file.txt
- Load the file as a plain text file.If no suffix is specified, the file will be loaded as a YAML file.
text_data: !include:txt text.txt
json_data: !include:json data.json
Relative paths are resolved relative to the directory of the file that contains the include.
You can use glob patterns in the file path, and all matching files will be included as a list.
files: !include:yaml "data/*.yaml"
You can use Jinja templating in your configuration file by using the !jinja
tag. The context available to the template is passed as an argument to the loader.
greeting: !jinja |
Hello, {{ name }}!
The !jinja
tag is a short form for !jinja:str
, a jinja template rendered as a string.
In addition to plain text templates, you can also render a template to native objects.
connection:
url: !env DB_URL
token_provider: !jinja:obj |
{{token_provider}}
When using !jinja:obj
the template is rendered using NativeEnvironment and the result is evaluated as a native object instead of a string.
FAQs
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.
Product
Socket now supports Scala and Kotlin, bringing AI-powered threat detection to JVM projects with easy manifest generation and fast, accurate scans.
Application Security
/Security News
Socket CEO Feross Aboukhadijeh and a16z partner Joel de la Garza discuss vibe coding, AI-driven software development, and how the rise of LLMs, despite their risks, still points toward a more secure and innovative future.
Research
/Security News
Threat actors hijacked Toptal’s GitHub org, publishing npm packages with malicious payloads that steal tokens and attempt to wipe victim systems.