wolfsoftware.data-converter


Namewolfsoftware.data-converter JSON
Version 0.1.0 PyPI version JSON
download
home_pagehttps://github.com/DevelopersToolbox/data-converter-package
SummaryA data converter package to convert data between JSON, YAML and XML.
upload_time2024-06-06 16:48:16
maintainerNone
docs_urlNone
authorWolf Software
requires_python>=3.9
licenseMIT
keywords python json xml
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            <!-- markdownlint-disable -->
<p align="center">
    <a href="https://github.com/DevelopersToolbox/">
        <img src="https://cdn.wolfsoftware.com/assets/images/github/organisations/developerstoolbox/black-and-white-circle-256.png" alt="DevelopersToolbox logo" />
    </a>
    <br />
    <a href="https://github.com/DevelopersToolbox/data-converter-package/actions/workflows/cicd.yml">
        <img src="https://img.shields.io/github/actions/workflow/status/DevelopersToolbox/data-converter-package/cicd.yml?branch=master&label=build%20status&style=for-the-badge" alt="Github Build Status" />
    </a>
    <a href="https://github.com/DevelopersToolbox/data-converter-package/blob/master/LICENSE.md">
        <img src="https://img.shields.io/github/license/DevelopersToolbox/data-converter-package?color=blue&label=License&style=for-the-badge" alt="License">
    </a>
    <a href="https://github.com/DevelopersToolbox/data-converter-package">
        <img src="https://img.shields.io/github/created-at/DevelopersToolbox/data-converter-package?color=blue&label=Created&style=for-the-badge" alt="Created">
    </a>
    <br />
    <a href="https://github.com/DevelopersToolbox/data-converter-package/releases/latest">
        <img src="https://img.shields.io/github/v/release/DevelopersToolbox/data-converter-package?color=blue&label=Latest%20Release&style=for-the-badge" alt="Release">
    </a>
    <a href="https://github.com/DevelopersToolbox/data-converter-package/releases/latest">
        <img src="https://img.shields.io/github/release-date/DevelopersToolbox/data-converter-package?color=blue&label=Released&style=for-the-badge" alt="Released">
    </a>
    <a href="https://github.com/DevelopersToolbox/data-converter-package/releases/latest">
        <img src="https://img.shields.io/github/commits-since/DevelopersToolbox/data-converter-package/latest.svg?color=blue&style=for-the-badge" alt="Commits since release">
    </a>
    <br />
    <a href="https://github.com/DevelopersToolbox/data-converter-package/blob/master/.github/CODE_OF_CONDUCT.md">
        <img src="https://img.shields.io/badge/Code%20of%20Conduct-blue?style=for-the-badge" />
    </a>
    <a href="https://github.com/DevelopersToolbox/data-converter-package/blob/master/.github/CONTRIBUTING.md">
        <img src="https://img.shields.io/badge/Contributing-blue?style=for-the-badge" />
    </a>
    <a href="https://github.com/DevelopersToolbox/data-converter-package/blob/master/.github/SECURITY.md">
        <img src="https://img.shields.io/badge/Report%20Security%20Concern-blue?style=for-the-badge" />
    </a>
    <a href="https://github.com/DevelopersToolbox/data-converter-package/issues">
        <img src="https://img.shields.io/badge/Get%20Support-blue?style=for-the-badge" />
    </a>
</p>

## Overview

The `wolfsoftware.data-converter` module provides functionalities for converting data between JSON, XML, and YAML formats.
It includes methods to convert dictionaries to and from these formats, making it a versatile tool for data transformation in Python applications.

## Installation

First, install the package using pip:

```bash
pip install wolfsoftware.data-converter
```

## Usage

### Importing the Module

To use the `DataConverter` class, import it from the `wolfsoftware.data_converter` package:

```python
from wolfsoftware.data_converter import DataConverter, DataConverterError
```

### Initializing the DataConverter

The `DataConverter` class requires data and its type as parameters during initialization. Supported data types are `json`, `xml`, `dict`, and `yaml`.

```python
# JSON data example
json_data = '{"name": "John", "age": 30}'
converter = DataConverter(json_data, data_type='json')

# XML data example
xml_data = '<person><name>John</name><age>30</age></person>'
converter = DataConverter(xml_data, data_type='xml')

# Dictionary data example
dict_data = {'name': 'John', 'age': 30}
converter = DataConverter(dict_data, data_type='dict')

# YAML data example
yaml_data = 'name: John\nage: 30\n'
converter = DataConverter(yaml_data, data_type='yaml')
```

### Converting Data

#### To JSON

Convert the data to JSON format using the `to_json` method:

```python
json_output = converter.to_json()
print(json_output)
```

#### To XML

Convert the data to XML format using the `to_xml` method:

```python
xml_output = converter.to_xml()
print(xml_output)
```

#### To YAML

Convert the data to YAML format using the `to_yaml` method:

```python
yaml_output = converter.to_yaml()
print(yaml_output)
```

### Example Usage

Here's a complete example demonstrating how to convert a dictionary to JSON, XML, and YAML formats:

```python
from wolfsoftware.data_converter import DataConverter, DataConverterError

# Dictionary data
data = {'name': 'John', 'age': 30}

# Initialize DataConverter
converter = DataConverter(data, data_type='dict')

# Convert to JSON
json_output = converter.to_json()
print("JSON Output:")
print(json_output)

# Convert to XML
xml_output = converter.to_xml()
print("XML Output:")
print(xml_output)

# Convert to YAML
yaml_output = converter.to_yaml()
print("YAML Output:")
print(yaml_output)
```

### Handling Unsupported Data Types

If an unsupported data type is provided, a `DataConverterError` will be raised:

```python
try:
    converter = DataConverter(data, data_type='unsupported')
except DataConverterError as e:
    print(f"Error: {e}")
```

<br />
<p align="right"><a href="https://wolfsoftware.com/"><img src="https://img.shields.io/badge/Created%20by%20Wolf%20on%20behalf%20of%20Wolf%20Software-blue?style=for-the-badge" /></a></p>

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/DevelopersToolbox/data-converter-package",
    "name": "wolfsoftware.data-converter",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.9",
    "maintainer_email": null,
    "keywords": "python, json, xml",
    "author": "Wolf Software",
    "author_email": "pypi@wolfsoftware.com",
    "download_url": "https://files.pythonhosted.org/packages/d2/cb/d56e32233fc6d1fb2102006b0bab4098dd054bc3671cb64b373d0990ed8f/wolfsoftware_data_converter-0.1.0.tar.gz",
    "platform": null,
    "description": "<!-- markdownlint-disable -->\n<p align=\"center\">\n    <a href=\"https://github.com/DevelopersToolbox/\">\n        <img src=\"https://cdn.wolfsoftware.com/assets/images/github/organisations/developerstoolbox/black-and-white-circle-256.png\" alt=\"DevelopersToolbox logo\" />\n    </a>\n    <br />\n    <a href=\"https://github.com/DevelopersToolbox/data-converter-package/actions/workflows/cicd.yml\">\n        <img src=\"https://img.shields.io/github/actions/workflow/status/DevelopersToolbox/data-converter-package/cicd.yml?branch=master&label=build%20status&style=for-the-badge\" alt=\"Github Build Status\" />\n    </a>\n    <a href=\"https://github.com/DevelopersToolbox/data-converter-package/blob/master/LICENSE.md\">\n        <img src=\"https://img.shields.io/github/license/DevelopersToolbox/data-converter-package?color=blue&label=License&style=for-the-badge\" alt=\"License\">\n    </a>\n    <a href=\"https://github.com/DevelopersToolbox/data-converter-package\">\n        <img src=\"https://img.shields.io/github/created-at/DevelopersToolbox/data-converter-package?color=blue&label=Created&style=for-the-badge\" alt=\"Created\">\n    </a>\n    <br />\n    <a href=\"https://github.com/DevelopersToolbox/data-converter-package/releases/latest\">\n        <img src=\"https://img.shields.io/github/v/release/DevelopersToolbox/data-converter-package?color=blue&label=Latest%20Release&style=for-the-badge\" alt=\"Release\">\n    </a>\n    <a href=\"https://github.com/DevelopersToolbox/data-converter-package/releases/latest\">\n        <img src=\"https://img.shields.io/github/release-date/DevelopersToolbox/data-converter-package?color=blue&label=Released&style=for-the-badge\" alt=\"Released\">\n    </a>\n    <a href=\"https://github.com/DevelopersToolbox/data-converter-package/releases/latest\">\n        <img src=\"https://img.shields.io/github/commits-since/DevelopersToolbox/data-converter-package/latest.svg?color=blue&style=for-the-badge\" alt=\"Commits since release\">\n    </a>\n    <br />\n    <a href=\"https://github.com/DevelopersToolbox/data-converter-package/blob/master/.github/CODE_OF_CONDUCT.md\">\n        <img src=\"https://img.shields.io/badge/Code%20of%20Conduct-blue?style=for-the-badge\" />\n    </a>\n    <a href=\"https://github.com/DevelopersToolbox/data-converter-package/blob/master/.github/CONTRIBUTING.md\">\n        <img src=\"https://img.shields.io/badge/Contributing-blue?style=for-the-badge\" />\n    </a>\n    <a href=\"https://github.com/DevelopersToolbox/data-converter-package/blob/master/.github/SECURITY.md\">\n        <img src=\"https://img.shields.io/badge/Report%20Security%20Concern-blue?style=for-the-badge\" />\n    </a>\n    <a href=\"https://github.com/DevelopersToolbox/data-converter-package/issues\">\n        <img src=\"https://img.shields.io/badge/Get%20Support-blue?style=for-the-badge\" />\n    </a>\n</p>\n\n## Overview\n\nThe `wolfsoftware.data-converter` module provides functionalities for converting data between JSON, XML, and YAML formats.\nIt includes methods to convert dictionaries to and from these formats, making it a versatile tool for data transformation in Python applications.\n\n## Installation\n\nFirst, install the package using pip:\n\n```bash\npip install wolfsoftware.data-converter\n```\n\n## Usage\n\n### Importing the Module\n\nTo use the `DataConverter` class, import it from the `wolfsoftware.data_converter` package:\n\n```python\nfrom wolfsoftware.data_converter import DataConverter, DataConverterError\n```\n\n### Initializing the DataConverter\n\nThe `DataConverter` class requires data and its type as parameters during initialization. Supported data types are `json`, `xml`, `dict`, and `yaml`.\n\n```python\n# JSON data example\njson_data = '{\"name\": \"John\", \"age\": 30}'\nconverter = DataConverter(json_data, data_type='json')\n\n# XML data example\nxml_data = '<person><name>John</name><age>30</age></person>'\nconverter = DataConverter(xml_data, data_type='xml')\n\n# Dictionary data example\ndict_data = {'name': 'John', 'age': 30}\nconverter = DataConverter(dict_data, data_type='dict')\n\n# YAML data example\nyaml_data = 'name: John\\nage: 30\\n'\nconverter = DataConverter(yaml_data, data_type='yaml')\n```\n\n### Converting Data\n\n#### To JSON\n\nConvert the data to JSON format using the `to_json` method:\n\n```python\njson_output = converter.to_json()\nprint(json_output)\n```\n\n#### To XML\n\nConvert the data to XML format using the `to_xml` method:\n\n```python\nxml_output = converter.to_xml()\nprint(xml_output)\n```\n\n#### To YAML\n\nConvert the data to YAML format using the `to_yaml` method:\n\n```python\nyaml_output = converter.to_yaml()\nprint(yaml_output)\n```\n\n### Example Usage\n\nHere's a complete example demonstrating how to convert a dictionary to JSON, XML, and YAML formats:\n\n```python\nfrom wolfsoftware.data_converter import DataConverter, DataConverterError\n\n# Dictionary data\ndata = {'name': 'John', 'age': 30}\n\n# Initialize DataConverter\nconverter = DataConverter(data, data_type='dict')\n\n# Convert to JSON\njson_output = converter.to_json()\nprint(\"JSON Output:\")\nprint(json_output)\n\n# Convert to XML\nxml_output = converter.to_xml()\nprint(\"XML Output:\")\nprint(xml_output)\n\n# Convert to YAML\nyaml_output = converter.to_yaml()\nprint(\"YAML Output:\")\nprint(yaml_output)\n```\n\n### Handling Unsupported Data Types\n\nIf an unsupported data type is provided, a `DataConverterError` will be raised:\n\n```python\ntry:\n    converter = DataConverter(data, data_type='unsupported')\nexcept DataConverterError as e:\n    print(f\"Error: {e}\")\n```\n\n<br />\n<p align=\"right\"><a href=\"https://wolfsoftware.com/\"><img src=\"https://img.shields.io/badge/Created%20by%20Wolf%20on%20behalf%20of%20Wolf%20Software-blue?style=for-the-badge\" /></a></p>\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "A data converter package to convert data between JSON, YAML and XML.",
    "version": "0.1.0",
    "project_urls": {
        "Documentation": "https://github.com/DevelopersToolbox/data-converter-package",
        "Homepage": "https://github.com/DevelopersToolbox/data-converter-package",
        "Source": "https://github.com/DevelopersToolbox/data-converter-package",
        "Sponsor": "https://github.com/sponsors/WolfSoftware",
        "Tracker": "https://github.com/wDevelopersToolbox/data-converter-package/issues/"
    },
    "split_keywords": [
        "python",
        " json",
        " xml"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "983b0999688500c9ca25816166c2a7f136809ef36923b73e5ab3e7c0255bb0fe",
                "md5": "1e87f500e43e77b00ff6165c914ed938",
                "sha256": "901b873da4e28c470bad8e94fb469c18f2a2d6f31ede3b0ab238db16ef6cf858"
            },
            "downloads": -1,
            "filename": "wolfsoftware.data_converter-0.1.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "1e87f500e43e77b00ff6165c914ed938",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.9",
            "size": 6777,
            "upload_time": "2024-06-06T16:48:14",
            "upload_time_iso_8601": "2024-06-06T16:48:14.609194Z",
            "url": "https://files.pythonhosted.org/packages/98/3b/0999688500c9ca25816166c2a7f136809ef36923b73e5ab3e7c0255bb0fe/wolfsoftware.data_converter-0.1.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "d2cbd56e32233fc6d1fb2102006b0bab4098dd054bc3671cb64b373d0990ed8f",
                "md5": "58165f8330af21e7ca98f8f4274158b5",
                "sha256": "f82e2398038a1b6921a509d967e8065182c12e08066d82b4afd598cafc48ae78"
            },
            "downloads": -1,
            "filename": "wolfsoftware_data_converter-0.1.0.tar.gz",
            "has_sig": false,
            "md5_digest": "58165f8330af21e7ca98f8f4274158b5",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.9",
            "size": 8858,
            "upload_time": "2024-06-06T16:48:16",
            "upload_time_iso_8601": "2024-06-06T16:48:16.532244Z",
            "url": "https://files.pythonhosted.org/packages/d2/cb/d56e32233fc6d1fb2102006b0bab4098dd054bc3671cb64b373d0990ed8f/wolfsoftware_data_converter-0.1.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-06-06 16:48:16",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "DevelopersToolbox",
    "github_project": "data-converter-package",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "requirements": [],
    "lcname": "wolfsoftware.data-converter"
}
        
Elapsed time: 0.26417s