All Projects → tanbro → pyyaml-include

tanbro / pyyaml-include

Licence: GPL-3.0 License
yaml include other yaml

Programming Languages

python
139335 projects - #7 most used programming language
Jinja
831 projects

Projects that are alternatives of or similar to pyyaml-include

python-yamlable
A thin wrapper of PyYaml to convert Python objects to YAML and back
Stars: ✭ 28 (-42.86%)
Mutual labels:  yaml, pyyaml
pyaml env
Parse YAML configuration with environment variables in Python
Stars: ✭ 36 (-26.53%)
Mutual labels:  yaml, pyyaml
Config
PHP library for simple configuration management
Stars: ✭ 39 (-20.41%)
Mutual labels:  yaml
doo
简单易用的接口管理解决方案,支持接口文档管理、Mock服务,接口测试等功能。接口文档采用 yaml 或 Excel 格式书写,简单快捷,Mock 基于该文档,无需数据库,一条命令秒变 Mock 服务。
Stars: ✭ 36 (-26.53%)
Mutual labels:  yaml
yamlful
YAML-based HTTP client code generation
Stars: ✭ 77 (+57.14%)
Mutual labels:  yaml
gsheet to arb
Import translations (ARB/Dart) from Google Sheets
Stars: ✭ 21 (-57.14%)
Mutual labels:  yaml
yaml-front-matter
A to the point yaml front matter parser
Stars: ✭ 200 (+308.16%)
Mutual labels:  yaml
goodconf
Transparently load variables from environment or JSON/YAML file.
Stars: ✭ 80 (+63.27%)
Mutual labels:  yaml
yajsv
Yet Another JSON Schema Validator [CLI]
Stars: ✭ 42 (-14.29%)
Mutual labels:  yaml
openapiclientgen
Generate C# and TypeScript client codes from Open API / Swagger definitions
Stars: ✭ 31 (-36.73%)
Mutual labels:  yaml
CoreFormatters
.NET Core Custom Formatter for Yaml
Stars: ✭ 21 (-57.14%)
Mutual labels:  yaml
python-yamlordereddictloader
(DEPRECATED) YAML loader and dumper for PyYAML allowing to keep keys order.
Stars: ✭ 25 (-48.98%)
Mutual labels:  yaml
crystalizer
(De)serialize any Crystal object - out of the box. Supports JSON, YAML and Byte format.
Stars: ✭ 32 (-34.69%)
Mutual labels:  yaml
examples
Example Prismatic components and integrations
Stars: ✭ 23 (-53.06%)
Mutual labels:  yaml
dby
Simple Yaml DB
Stars: ✭ 47 (-4.08%)
Mutual labels:  yaml
PotentCodables
🧪 PotentCodables - A potent set of implementations and extensions to the Swift Codable system
Stars: ✭ 32 (-34.69%)
Mutual labels:  yaml
yaask
Make your yaml configurable with interactive configurations!
Stars: ✭ 15 (-69.39%)
Mutual labels:  yaml
counsel-jq
Traverse complex JSON and YAML structures with live feedback
Stars: ✭ 99 (+102.04%)
Mutual labels:  yaml
dataconf
Simple dataclasses configuration management for Python with hocon/json/yaml/properties/env-vars/dict support.
Stars: ✭ 40 (-18.37%)
Mutual labels:  yaml
online-resume
A Jekyll theme for resume / cv based on Markdown. Demo: https://tarrex.github.io/online-resume
Stars: ✭ 27 (-44.9%)
Mutual labels:  yaml

pyyaml-include

GitHub tag Python Package Documentation Status Quality Gate Status PyPI PyPI - License PyPI - Format PyPI - Status PyPI - Python Version PyPI - Implementation

An extending constructor of PyYAML: include YAML files into YAML document.

Install

pip install pyyaml-include

Usage

Consider we have such YAML files:

├── 0.yml
└── include.d
    ├── 1.yml
    └── 2.yml
  • 1.yml 's content:

    name: "1"
  • 2.yml 's content:

    name: "2"

To include 1.yml, 2.yml in 0.yml, we shall add YamlIncludeConstructor to PyYAML's loader, then add an !include tag in 0.yaml:

import yaml
from yamlinclude import YamlIncludeConstructor

YamlIncludeConstructor.add_to_loader_class(loader_class=yaml.FullLoader, base_dir='/your/conf/dir')

with open('0.yml') as f:
    data = yaml.load(f, Loader=yaml.FullLoader)

print(data)

Mapping

If 0.yml was:

file1: !include include.d/1.yml
file2: !include include.d/2.yml

We'll get:

file1:
  name: "1"
file2:
  name: "2"

Sequence

If 0.yml was:

files:
  - !include include.d/1.yml
  - !include include.d/2.yml

We'll get:

files:
  - name: "1"
  - name: "2"

Note:

File name can be either absolute (like /usr/conf/1.5/Make.yml) or relative (like ../../cfg/img.yml).

Wildcards

File name can contain shell-style wildcards. Data loaded from the file(s) found by wildcards will be set in a sequence.

That is to say, a list will be returned when including file name contains wildcards. Length of the returned list equals number of matched files:

  • when only 1 file matched, length of list will be 1
  • when there are no files matched, an empty list will be returned

If 0.yml was:

files: !include include.d/*.yml

We'll get:

files:
  - name: "1"
  - name: "2"

Note:

  • For Python>=3.5, if recursive argument of !include YAML tag is true, the pattern “**” will match any files and zero or more directories and subdirectories.
  • Using the “**” pattern in large directory trees may consume an inordinate amount of time because of recursive search.

In order to enable recursive argument, we shall set it in Mapping or Sequence arguments mode:

  • Arguments in Sequence mode:

    !include [tests/data/include.d/**/*.yml, true]
  • Arguments in Mapping mode:

    !include {pathname: tests/data/include.d/**/*.yml, recursive: true}

Non YAML files

This extending constructor can now load data from non YAML files, supported file types are:

  • json
  • toml (only available when toml installed)
  • ini

The constructor read non YAML files by different readers according to a pattern table defined in src/yamlinclude/readers.py.

Default reader table can be replaced by a custom reader_map when call add_to_loader_class.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].