yamling


Nameyamling JSON
Version 1.8.4 PyPI version JSON
download
home_pageNone
SummaryEnhanced YAML loading and dumping.
upload_time2025-02-18 02:24:09
maintainerNone
docs_urlNone
authorNone
requires_python>=3.12
licenseMIT License Copyright (c) 2024, Philipp Temminghoff Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
keywords pyyaml include serialization yaml yml
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # yamling

[![PyPI License](https://img.shields.io/pypi/l/yamling.svg)](https://pypi.org/project/yamling/)
[![Package status](https://img.shields.io/pypi/status/yamling.svg)](https://pypi.org/project/yamling/)
[![Daily downloads](https://img.shields.io/pypi/dd/yamling.svg)](https://pypi.org/project/yamling/)
[![Weekly downloads](https://img.shields.io/pypi/dw/yamling.svg)](https://pypi.org/project/yamling/)
[![Monthly downloads](https://img.shields.io/pypi/dm/yamling.svg)](https://pypi.org/project/yamling/)
[![Distribution format](https://img.shields.io/pypi/format/yamling.svg)](https://pypi.org/project/yamling/)
[![Wheel availability](https://img.shields.io/pypi/wheel/yamling.svg)](https://pypi.org/project/yamling/)
[![Python version](https://img.shields.io/pypi/pyversions/yamling.svg)](https://pypi.org/project/yamling/)
[![Implementation](https://img.shields.io/pypi/implementation/yamling.svg)](https://pypi.org/project/yamling/)
[![Releases](https://img.shields.io/github/downloads/phil65/yamling/total.svg)](https://github.com/phil65/yamling/releases)
[![Github Contributors](https://img.shields.io/github/contributors/phil65/yamling)](https://github.com/phil65/yamling/graphs/contributors)
[![Github Discussions](https://img.shields.io/github/discussions/phil65/yamling)](https://github.com/phil65/yamling/discussions)
[![Github Forks](https://img.shields.io/github/forks/phil65/yamling)](https://github.com/phil65/yamling/forks)
[![Github Issues](https://img.shields.io/github/issues/phil65/yamling)](https://github.com/phil65/yamling/issues)
[![Github Issues](https://img.shields.io/github/issues-pr/phil65/yamling)](https://github.com/phil65/yamling/pulls)
[![Github Watchers](https://img.shields.io/github/watchers/phil65/yamling)](https://github.com/phil65/yamling/watchers)
[![Github Stars](https://img.shields.io/github/stars/phil65/yamling)](https://github.com/phil65/yamling/stars)
[![Github Repository size](https://img.shields.io/github/repo-size/phil65/yamling)](https://github.com/phil65/yamling)
[![Github last commit](https://img.shields.io/github/last-commit/phil65/yamling)](https://github.com/phil65/yamling/commits)
[![Github release date](https://img.shields.io/github/release-date/phil65/yamling)](https://github.com/phil65/yamling/releases)
[![Github language count](https://img.shields.io/github/languages/count/phil65/yamling)](https://github.com/phil65/yamling)
[![Github commits this week](https://img.shields.io/github/commit-activity/w/phil65/yamling)](https://github.com/phil65/yamling)
[![Github commits this month](https://img.shields.io/github/commit-activity/m/phil65/yamling)](https://github.com/phil65/yamling)
[![Github commits this year](https://img.shields.io/github/commit-activity/y/phil65/yamling)](https://github.com/phil65/yamling)
[![Package status](https://codecov.io/gh/phil65/yamling/branch/main/graph/badge.svg)](https://codecov.io/gh/phil65/yamling/)
[![Code style: black](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/psf/black)
[![PyUp](https://pyup.io/repos/github/phil65/yamling/shield.svg)](https://pyup.io/repos/github/phil65/yamling/)

[Read the documentation!](https://phil65.github.io/yamling/)


Yamling is a YAML handling library that provides enhanced loading and dumping capabilities for YAML files. It builds upon [PyYAML](https://pyyaml.org/) to offer additional features like environment variable support, file inclusion, and Jinja2 template resolution.
Special mentions also to `pyyaml_env_tag` as well as `pyyaml-include`, this library exposes these YAML extensions with a unified interface.

## Loading YAML

### Basic Loading

To load YAML content from a string:

```python
from yamling import load_yaml

# Simple YAML loading
data = load_yaml("""
name: John
age: 30
""")
```

To load from a file:

```python
from yamling import load_yaml_file

# Load from local file
config = load_yaml_file("config.yaml")

# Load from remote file (S3, HTTP, etc.)
remote_config = load_yaml_file("s3://bucket/config.yaml")
```

### Safety Modes

Yamling supports three safety modes when loading YAML:

```python
# Safe mode - most restrictive, recommended for untrusted input
data = load_yaml(content, mode="safe")

# Full mode - allows some additional types but restricts dangerous ones
data = load_yaml(content, mode="full")

# Unsafe mode - allows all YAML features (default)
data = load_yaml(content, mode="unsafe")
```

> **Warning**
> Always use "safe" mode when loading untrusted YAML content to prevent code execution vulnerabilities.

### File Inclusion

Yamling supports including other YAML files using the `!include` tag:

```yaml
# main.yaml
database:
  !include db_config.yaml
logging:
  !include logging_config.yaml
```

When loading, specify the base path for includes:

```python
config = load_yaml_file("main.yaml", include_base_path="configs/")
```

### Environment Variables

Use the `!ENV` tag to reference environment variables:

```yaml
database:
  password: !ENV DB_PASSWORD
  host: !ENV ${DB_HOST:localhost}  # with default value
```

### Template Resolution

Yamling can resolve [Jinja2](https://jinja.palletsprojects.com/) templates in YAML:

```python
from jinja2 import Environment
import yamling

env = Environment()
yaml_content = """
message: "Hello {{ name }}!"
"""

data = load_yaml(
    yaml_content,
    resolve_strings=True,
    jinja_env=env
)
```

### Inheritance

YAML files can inherit from other files using the `INHERIT` key. You can specify either a single file or a list of files to inherit from:

```yaml
# Single inheritance
# prod.yaml
INHERIT: base.yaml
database:
  host: prod.example.com

# Multiple inheritance
# prod_with_logging.yaml
INHERIT:
  - base.yaml
  - logging.yaml
  - monitoring.yaml
database:
  host: prod.example.com
```

When using multiple inheritance, files are processed in order, with later files taking precedence over earlier ones. The current file's values take precedence over all inherited values.

For example:

```yaml
# base.yaml
database:
  host: localhost
  port: 5432
  timeout: 30

# logging.yaml
database:
  timeout: 60
logging:
  level: INFO

# prod.yaml
INHERIT:
  - base.yaml
  - logging.yaml
database:
  host: prod.example.com
```

When loading `prod.yaml`, the final configuration will be:

```yaml
database:
  host: prod.example.com  # from prod.yaml
  port: 5432             # from base.yaml
  timeout: 60            # from logging.yaml
logging:
  level: INFO            # from logging.yaml
```

Load with inheritance enabled:

```python
config = load_yaml_file("prod.yaml", resolve_inherit=True)
```


## Dumping YAML

To serialize Python objects to YAML:

```python
from yamling import dump_yaml

data = {
    "name": "John",
    "scores": [1, 2, 3],
    "active": True
}

yaml_string = dump_yaml(data)
```
Dataclasses and Pydantic v2 models can also get dumped.

### Custom Class Mapping

Map custom classes to built-in types for YAML representation:

```python
from collections import OrderedDict

data = OrderedDict([("b", 2), ("a", 1)])
yaml_string = dump_yaml(data, class_mappings={OrderedDict: dict})
```

## Custom Loader Configuration

For advanced use cases, you can create a custom loader:

```python
from yamling import get_loader
import yaml

# Create custom loader with specific features
loader_cls = get_loader(
    yaml.SafeLoader,
    include_base_path="configs/",
    enable_include=True,
    enable_env=True,
    resolve_strings=True,
    jinja_env=jinja_env,
    type_converters={int: str}
)

# Use custom loader
data = yaml.load(content, Loader=loader_cls)
```

## Custom Tag Handling

Yamling provides a `YAMLParser` class for handling custom YAML tags. This allows you to define how specific tagged values should be processed during YAML loading.

### Basic Tag Registration

You can register tag handlers using either a decorator or explicit registration:

```python
from yamling import YAMLParser

# Create parser instance
yaml_parser = YAMLParser()

# register handler
def handle_uppercase(data: str) -> str:
    return data.upper()

yaml_parser.register_handler("uppercase", handle_uppercase)
```

### Using Custom Tags

Once registered, you can use the custom tags in your YAML:

```yaml
# config.yaml
message: !uppercase "hello world"
```

Load the YAML using the parser:

```python
# Load from string
data = yaml_parser.load_yaml("""
message: !uppercase "hello world"
""")

# Or load from file
data = yaml_parser.load_yaml_file("config.yaml")

print(data["message"])  # "HELLO WORLD"
```

### Class Registration

For simple cases where you just want to convert tagged dictionary data into class instances,
you can use the `register_class` method. The method will automatically use the lowercase class name
as the tag name (following YAML tag conventions), but you can override this with a custom tag name:

```python
from yamling import YAMLParser
from dataclasses import dataclass

@dataclass
class Person:
    name: str
    age: int

@dataclass
class HomeAddress:
    street: str
    city: str

yaml_parser = YAMLParser()

# Register using class name as tag (will use "person" as tag)
yaml_parser.register_class(Person)

# Register with custom tag name instead of "homeaddress"
yaml_parser.register_class(HomeAddress, "address")

# Now you can use it in YAML:
data = yaml_parser.load_yaml("""
user: !person
  name: John Doe
  age: 30
home: !address
  street: 123 Main St
  city: New York
""")

print(data["user"])    # Person(name='John Doe', age=30)
print(data["home"])    # HomeAddress(street='123 Main St', city='New York')
```

### Complex Structures

Custom tags can be used in nested structures and lists:

```yaml
team:
  manager: !person
    name: Alice Smith
    age: 45
  members:
    - !person
      name: Bob Johnson
      age: 30
    - !person
      name: Carol White
      age: 28
messages:
  - !uppercase "welcome"
  - !uppercase "goodbye"
```

### Combining with Other Features

The `YAMLParser` class supports all of Yamling's standard features:

```python
data = yaml_parser.load_yaml_file(
    "config.yaml",
    mode="safe",                    # Safety mode
    include_base_path="configs/",   # For !include directives
    resolve_strings=True,           # Enable Jinja2 template resolution
    resolve_inherit=True,           # Enable inheritance
    jinja_env=jinja_env           # Custom Jinja2 environment
)
```

### Available Tags

You can list all registered tags:

```python
tags = yaml_parser.list_tags()
print(tags)  # ['!person', '!uppercase']
```


## Universal load / dump interface

Yamling provides a universal load function that can handle YAML, JSON, TOML, and INI files.
Apart from yaml, only stdlib modules are used, so no additional dependencies are required.
Here's a simple example:

```python
import yamling

# Load files based on their extension
config = yamling.load_file("config.yaml")    # YAML
settings = yamling.load_file("settings.json") # JSON
params = yamling.load_file("params.toml")    # TOML

# Or explicitly specify the format
data = yamling.load_file("config.txt", mode="yaml")

# Load directly from strings
yaml_text = """
name: John
age: 30
"""
data = yamling.load(yaml_text, mode="yaml")
# same in other direction
json_text = yamling.dump(data, mode="json")
yaml.dump_file("config.yaml", data)
```

> **Note**
> If [orjson](https://github.com/ijl/orjson) is installed, the loader will automatically use it for JSON parsing / dumping, offering significantly better performance compared to the standard `json` module.

            

Raw data

            {
    "_id": null,
    "home_page": null,
    "name": "yamling",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.12",
    "maintainer_email": null,
    "keywords": "PyYAML, include, serialization, yaml, yml",
    "author": null,
    "author_email": "Philipp Temminghoff <philipptemminghoff@googlemail.com>",
    "download_url": "https://files.pythonhosted.org/packages/56/43/a373808cc67c60dd3e569868ab4fa193c957922634c3aee6313053523c54/yamling-1.8.4.tar.gz",
    "platform": null,
    "description": "# yamling\n\n[![PyPI License](https://img.shields.io/pypi/l/yamling.svg)](https://pypi.org/project/yamling/)\n[![Package status](https://img.shields.io/pypi/status/yamling.svg)](https://pypi.org/project/yamling/)\n[![Daily downloads](https://img.shields.io/pypi/dd/yamling.svg)](https://pypi.org/project/yamling/)\n[![Weekly downloads](https://img.shields.io/pypi/dw/yamling.svg)](https://pypi.org/project/yamling/)\n[![Monthly downloads](https://img.shields.io/pypi/dm/yamling.svg)](https://pypi.org/project/yamling/)\n[![Distribution format](https://img.shields.io/pypi/format/yamling.svg)](https://pypi.org/project/yamling/)\n[![Wheel availability](https://img.shields.io/pypi/wheel/yamling.svg)](https://pypi.org/project/yamling/)\n[![Python version](https://img.shields.io/pypi/pyversions/yamling.svg)](https://pypi.org/project/yamling/)\n[![Implementation](https://img.shields.io/pypi/implementation/yamling.svg)](https://pypi.org/project/yamling/)\n[![Releases](https://img.shields.io/github/downloads/phil65/yamling/total.svg)](https://github.com/phil65/yamling/releases)\n[![Github Contributors](https://img.shields.io/github/contributors/phil65/yamling)](https://github.com/phil65/yamling/graphs/contributors)\n[![Github Discussions](https://img.shields.io/github/discussions/phil65/yamling)](https://github.com/phil65/yamling/discussions)\n[![Github Forks](https://img.shields.io/github/forks/phil65/yamling)](https://github.com/phil65/yamling/forks)\n[![Github Issues](https://img.shields.io/github/issues/phil65/yamling)](https://github.com/phil65/yamling/issues)\n[![Github Issues](https://img.shields.io/github/issues-pr/phil65/yamling)](https://github.com/phil65/yamling/pulls)\n[![Github Watchers](https://img.shields.io/github/watchers/phil65/yamling)](https://github.com/phil65/yamling/watchers)\n[![Github Stars](https://img.shields.io/github/stars/phil65/yamling)](https://github.com/phil65/yamling/stars)\n[![Github Repository size](https://img.shields.io/github/repo-size/phil65/yamling)](https://github.com/phil65/yamling)\n[![Github last commit](https://img.shields.io/github/last-commit/phil65/yamling)](https://github.com/phil65/yamling/commits)\n[![Github release date](https://img.shields.io/github/release-date/phil65/yamling)](https://github.com/phil65/yamling/releases)\n[![Github language count](https://img.shields.io/github/languages/count/phil65/yamling)](https://github.com/phil65/yamling)\n[![Github commits this week](https://img.shields.io/github/commit-activity/w/phil65/yamling)](https://github.com/phil65/yamling)\n[![Github commits this month](https://img.shields.io/github/commit-activity/m/phil65/yamling)](https://github.com/phil65/yamling)\n[![Github commits this year](https://img.shields.io/github/commit-activity/y/phil65/yamling)](https://github.com/phil65/yamling)\n[![Package status](https://codecov.io/gh/phil65/yamling/branch/main/graph/badge.svg)](https://codecov.io/gh/phil65/yamling/)\n[![Code style: black](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/psf/black)\n[![PyUp](https://pyup.io/repos/github/phil65/yamling/shield.svg)](https://pyup.io/repos/github/phil65/yamling/)\n\n[Read the documentation!](https://phil65.github.io/yamling/)\n\n\nYamling is a YAML handling library that provides enhanced loading and dumping capabilities for YAML files. It builds upon [PyYAML](https://pyyaml.org/) to offer additional features like environment variable support, file inclusion, and Jinja2 template resolution.\nSpecial mentions also to `pyyaml_env_tag` as well as `pyyaml-include`, this library exposes these YAML extensions with a unified interface.\n\n## Loading YAML\n\n### Basic Loading\n\nTo load YAML content from a string:\n\n```python\nfrom yamling import load_yaml\n\n# Simple YAML loading\ndata = load_yaml(\"\"\"\nname: John\nage: 30\n\"\"\")\n```\n\nTo load from a file:\n\n```python\nfrom yamling import load_yaml_file\n\n# Load from local file\nconfig = load_yaml_file(\"config.yaml\")\n\n# Load from remote file (S3, HTTP, etc.)\nremote_config = load_yaml_file(\"s3://bucket/config.yaml\")\n```\n\n### Safety Modes\n\nYamling supports three safety modes when loading YAML:\n\n```python\n# Safe mode - most restrictive, recommended for untrusted input\ndata = load_yaml(content, mode=\"safe\")\n\n# Full mode - allows some additional types but restricts dangerous ones\ndata = load_yaml(content, mode=\"full\")\n\n# Unsafe mode - allows all YAML features (default)\ndata = load_yaml(content, mode=\"unsafe\")\n```\n\n> **Warning**\n> Always use \"safe\" mode when loading untrusted YAML content to prevent code execution vulnerabilities.\n\n### File Inclusion\n\nYamling supports including other YAML files using the `!include` tag:\n\n```yaml\n# main.yaml\ndatabase:\n  !include db_config.yaml\nlogging:\n  !include logging_config.yaml\n```\n\nWhen loading, specify the base path for includes:\n\n```python\nconfig = load_yaml_file(\"main.yaml\", include_base_path=\"configs/\")\n```\n\n### Environment Variables\n\nUse the `!ENV` tag to reference environment variables:\n\n```yaml\ndatabase:\n  password: !ENV DB_PASSWORD\n  host: !ENV ${DB_HOST:localhost}  # with default value\n```\n\n### Template Resolution\n\nYamling can resolve [Jinja2](https://jinja.palletsprojects.com/) templates in YAML:\n\n```python\nfrom jinja2 import Environment\nimport yamling\n\nenv = Environment()\nyaml_content = \"\"\"\nmessage: \"Hello {{ name }}!\"\n\"\"\"\n\ndata = load_yaml(\n    yaml_content,\n    resolve_strings=True,\n    jinja_env=env\n)\n```\n\n### Inheritance\n\nYAML files can inherit from other files using the `INHERIT` key. You can specify either a single file or a list of files to inherit from:\n\n```yaml\n# Single inheritance\n# prod.yaml\nINHERIT: base.yaml\ndatabase:\n  host: prod.example.com\n\n# Multiple inheritance\n# prod_with_logging.yaml\nINHERIT:\n  - base.yaml\n  - logging.yaml\n  - monitoring.yaml\ndatabase:\n  host: prod.example.com\n```\n\nWhen using multiple inheritance, files are processed in order, with later files taking precedence over earlier ones. The current file's values take precedence over all inherited values.\n\nFor example:\n\n```yaml\n# base.yaml\ndatabase:\n  host: localhost\n  port: 5432\n  timeout: 30\n\n# logging.yaml\ndatabase:\n  timeout: 60\nlogging:\n  level: INFO\n\n# prod.yaml\nINHERIT:\n  - base.yaml\n  - logging.yaml\ndatabase:\n  host: prod.example.com\n```\n\nWhen loading `prod.yaml`, the final configuration will be:\n\n```yaml\ndatabase:\n  host: prod.example.com  # from prod.yaml\n  port: 5432             # from base.yaml\n  timeout: 60            # from logging.yaml\nlogging:\n  level: INFO            # from logging.yaml\n```\n\nLoad with inheritance enabled:\n\n```python\nconfig = load_yaml_file(\"prod.yaml\", resolve_inherit=True)\n```\n\n\n## Dumping YAML\n\nTo serialize Python objects to YAML:\n\n```python\nfrom yamling import dump_yaml\n\ndata = {\n    \"name\": \"John\",\n    \"scores\": [1, 2, 3],\n    \"active\": True\n}\n\nyaml_string = dump_yaml(data)\n```\nDataclasses and Pydantic v2 models can also get dumped.\n\n### Custom Class Mapping\n\nMap custom classes to built-in types for YAML representation:\n\n```python\nfrom collections import OrderedDict\n\ndata = OrderedDict([(\"b\", 2), (\"a\", 1)])\nyaml_string = dump_yaml(data, class_mappings={OrderedDict: dict})\n```\n\n## Custom Loader Configuration\n\nFor advanced use cases, you can create a custom loader:\n\n```python\nfrom yamling import get_loader\nimport yaml\n\n# Create custom loader with specific features\nloader_cls = get_loader(\n    yaml.SafeLoader,\n    include_base_path=\"configs/\",\n    enable_include=True,\n    enable_env=True,\n    resolve_strings=True,\n    jinja_env=jinja_env,\n    type_converters={int: str}\n)\n\n# Use custom loader\ndata = yaml.load(content, Loader=loader_cls)\n```\n\n## Custom Tag Handling\n\nYamling provides a `YAMLParser` class for handling custom YAML tags. This allows you to define how specific tagged values should be processed during YAML loading.\n\n### Basic Tag Registration\n\nYou can register tag handlers using either a decorator or explicit registration:\n\n```python\nfrom yamling import YAMLParser\n\n# Create parser instance\nyaml_parser = YAMLParser()\n\n# register handler\ndef handle_uppercase(data: str) -> str:\n    return data.upper()\n\nyaml_parser.register_handler(\"uppercase\", handle_uppercase)\n```\n\n### Using Custom Tags\n\nOnce registered, you can use the custom tags in your YAML:\n\n```yaml\n# config.yaml\nmessage: !uppercase \"hello world\"\n```\n\nLoad the YAML using the parser:\n\n```python\n# Load from string\ndata = yaml_parser.load_yaml(\"\"\"\nmessage: !uppercase \"hello world\"\n\"\"\")\n\n# Or load from file\ndata = yaml_parser.load_yaml_file(\"config.yaml\")\n\nprint(data[\"message\"])  # \"HELLO WORLD\"\n```\n\n### Class Registration\n\nFor simple cases where you just want to convert tagged dictionary data into class instances,\nyou can use the `register_class` method. The method will automatically use the lowercase class name\nas the tag name (following YAML tag conventions), but you can override this with a custom tag name:\n\n```python\nfrom yamling import YAMLParser\nfrom dataclasses import dataclass\n\n@dataclass\nclass Person:\n    name: str\n    age: int\n\n@dataclass\nclass HomeAddress:\n    street: str\n    city: str\n\nyaml_parser = YAMLParser()\n\n# Register using class name as tag (will use \"person\" as tag)\nyaml_parser.register_class(Person)\n\n# Register with custom tag name instead of \"homeaddress\"\nyaml_parser.register_class(HomeAddress, \"address\")\n\n# Now you can use it in YAML:\ndata = yaml_parser.load_yaml(\"\"\"\nuser: !person\n  name: John Doe\n  age: 30\nhome: !address\n  street: 123 Main St\n  city: New York\n\"\"\")\n\nprint(data[\"user\"])    # Person(name='John Doe', age=30)\nprint(data[\"home\"])    # HomeAddress(street='123 Main St', city='New York')\n```\n\n### Complex Structures\n\nCustom tags can be used in nested structures and lists:\n\n```yaml\nteam:\n  manager: !person\n    name: Alice Smith\n    age: 45\n  members:\n    - !person\n      name: Bob Johnson\n      age: 30\n    - !person\n      name: Carol White\n      age: 28\nmessages:\n  - !uppercase \"welcome\"\n  - !uppercase \"goodbye\"\n```\n\n### Combining with Other Features\n\nThe `YAMLParser` class supports all of Yamling's standard features:\n\n```python\ndata = yaml_parser.load_yaml_file(\n    \"config.yaml\",\n    mode=\"safe\",                    # Safety mode\n    include_base_path=\"configs/\",   # For !include directives\n    resolve_strings=True,           # Enable Jinja2 template resolution\n    resolve_inherit=True,           # Enable inheritance\n    jinja_env=jinja_env           # Custom Jinja2 environment\n)\n```\n\n### Available Tags\n\nYou can list all registered tags:\n\n```python\ntags = yaml_parser.list_tags()\nprint(tags)  # ['!person', '!uppercase']\n```\n\n\n## Universal load / dump interface\n\nYamling provides a universal load function that can handle YAML, JSON, TOML, and INI files.\nApart from yaml, only stdlib modules are used, so no additional dependencies are required.\nHere's a simple example:\n\n```python\nimport yamling\n\n# Load files based on their extension\nconfig = yamling.load_file(\"config.yaml\")    # YAML\nsettings = yamling.load_file(\"settings.json\") # JSON\nparams = yamling.load_file(\"params.toml\")    # TOML\n\n# Or explicitly specify the format\ndata = yamling.load_file(\"config.txt\", mode=\"yaml\")\n\n# Load directly from strings\nyaml_text = \"\"\"\nname: John\nage: 30\n\"\"\"\ndata = yamling.load(yaml_text, mode=\"yaml\")\n# same in other direction\njson_text = yamling.dump(data, mode=\"json\")\nyaml.dump_file(\"config.yaml\", data)\n```\n\n> **Note**\n> If [orjson](https://github.com/ijl/orjson) is installed, the loader will automatically use it for JSON parsing / dumping, offering significantly better performance compared to the standard `json` module.\n",
    "bugtrack_url": null,
    "license": "MIT License\n        \n        Copyright (c) 2024, Philipp Temminghoff\n        \n        Permission is hereby granted, free of charge, to any person obtaining a copy\n        of this software and associated documentation files (the \"Software\"), to deal\n        in the Software without restriction, including without limitation the rights\n        to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n        copies of the Software, and to permit persons to whom the Software is\n        furnished to do so, subject to the following conditions:\n        \n        The above copyright notice and this permission notice shall be included in all\n        copies or substantial portions of the Software.\n        \n        THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n        IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n        FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n        AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n        LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n        OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\n        SOFTWARE.\n        ",
    "summary": "Enhanced YAML loading and dumping.",
    "version": "1.8.4",
    "project_urls": {
        "Code coverage": "https://app.codecov.io/gh/phil65/yamling",
        "Discussions": "https://github.com/phil65/yamling/discussions",
        "Documentation": "https://phil65.github.io/yamling/",
        "Issues": "https://github.com/phil65/yamling/issues",
        "Source": "https://github.com/phil65/yamling"
    },
    "split_keywords": [
        "pyyaml",
        " include",
        " serialization",
        " yaml",
        " yml"
    ],
    "urls": [
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "b2874df45bdc9ee9e490f9c2cfc8fb0023e1d1d90c2253de1d543f8612127663",
                "md5": "f7031370933bac883b0c3434febf0104",
                "sha256": "dd781b852d08e5338ff66440f3e4f819f7e1b90b8574c68ce1fc62303e9ed43b"
            },
            "downloads": -1,
            "filename": "yamling-1.8.4-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "f7031370933bac883b0c3434febf0104",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.12",
            "size": 25776,
            "upload_time": "2025-02-18T02:24:08",
            "upload_time_iso_8601": "2025-02-18T02:24:08.349348Z",
            "url": "https://files.pythonhosted.org/packages/b2/87/4df45bdc9ee9e490f9c2cfc8fb0023e1d1d90c2253de1d543f8612127663/yamling-1.8.4-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "5643a373808cc67c60dd3e569868ab4fa193c957922634c3aee6313053523c54",
                "md5": "4d7c9adcaee93f92fa3eee3ef5b8ef93",
                "sha256": "d591a60e4f526d0c62e01e006e474afe59fb973940f3b5d3ad22b607cba68dc0"
            },
            "downloads": -1,
            "filename": "yamling-1.8.4.tar.gz",
            "has_sig": false,
            "md5_digest": "4d7c9adcaee93f92fa3eee3ef5b8ef93",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.12",
            "size": 182688,
            "upload_time": "2025-02-18T02:24:09",
            "upload_time_iso_8601": "2025-02-18T02:24:09.827259Z",
            "url": "https://files.pythonhosted.org/packages/56/43/a373808cc67c60dd3e569868ab4fa193c957922634c3aee6313053523c54/yamling-1.8.4.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2025-02-18 02:24:09",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "phil65",
    "github_project": "yamling",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "lcname": "yamling"
}
        
Elapsed time: 2.00884s