configconverter


Nameconfigconverter JSON
Version 0.3.0 PyPI version JSON
download
home_pagehttps://github.com/ankitaglawe/configconverter
SummaryA versatile tool to convert configuration files between different formats.
upload_time2024-10-09 09:08:30
maintainerNone
docs_urlNone
authorAnkit Aglawe
requires_python<4.0,>=3.8
licenseMIT
keywords configuration converter json yaml toml ini xml
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # ConfigConverter

[![PyPI Version](https://img.shields.io/pypi/v/configconverter.svg)](https://pypi.org/project/configconverter/)
[![Python Versions](https://img.shields.io/pypi/pyversions/configconverter.svg)](https://pypi.org/project/configconverter/)
[![License](https://img.shields.io/pypi/l/configconverter.svg)](https://github.com/ankit-aglawe/configconverter/blob/main/LICENSE)
[![Documentation](https://img.shields.io/badge/docs-available-brightgreen.svg)](https://ankit-aglawe.github.io/configconverter/)

**ConfigConverter** is a powerful and easy-to-use tool designed to convert configuration files between various formats, including JSON, YAML, TOML, INI, and XML. 

## Features

- **Multi-Format Support:** Seamlessly convert between JSON, YAML, TOML, INI, and XML formats.
- **Command-Line Interface (CLI):** Perform conversions directly from your terminal with simple commands.
- **Python API:** Integrate conversion functionality into your Python projects effortlessly.
- **Extensible and Customizable:** Easily extend the tool to support additional formats or custom conversion logic.
- **User-Friendly:** Intuitive design ensures a smooth experience for both beginners and advanced users.

## Installation

### Via PyPI

Install ConfigConverter using `pip`:

```bash
pip install configconverter
```

### From Source

Clone the repository and install using Poetry:

```bash
git clone https://github.com/ankit-aglawe/configconverter.git
cd configconverter
poetry install
```

## Quick Start

### Command-Line Usage

Convert `config.json` to `config.yaml`:

```bash
configconverter config.json config.yaml
```

Specify input and output formats explicitly:

```bash
configconverter -i ini -o toml settings.conf settings.toml
```

Output the converted configuration to standard output:

```bash
configconverter config.toml -o json --stdout
```

### Python API Usage

#### Convert Using File Paths

```python
from configconverter import convert

# Convert JSON to YAML and save to a file
convert('config.json', 'json', 'yaml', output_file='config.yaml')
```

#### Convert Using Data Strings

```python
from configconverter import convert

# Convert JSON string to YAML string
json_data = '{"name": "John", "age": 30}'
yaml_data = convert(json_data, 'json', 'yaml', from_file=False)
print(yaml_data)
```

## Detailed Documentation

For comprehensive guides, advanced usage, and API references, visit the [ConfigConverter Documentation](https://ankit-aglawe.github.io/configconverter/).

## Examples

### Batch Conversion

Convert all JSON files in a directory to YAML:

```python
import os
from configconverter import convert

input_dir = 'json_configs'
output_dir = 'yaml_configs'
os.makedirs(output_dir, exist_ok=True)

for filename in os.listdir(input_dir):
    if filename.endswith('.json'):
        input_file = os.path.join(input_dir, filename)
        output_file = os.path.join(output_dir, filename.replace('.json', '.yaml'))
        convert(input_file, 'json', 'yaml', output_file=output_file)
```

### Custom Indentation

Convert a file with custom indentation:

```bash
configconverter config.json config.yaml --indent 2
```
### Handling Complex Data Structures

When dealing with configurations that contain complex nested structures or special data types, consider the following:

- **Avoid Incompatible Formats:** As INI format does not support nested structures, avoid converting complex configurations to INI.

- **Custom Serialization:** If you must convert to a format with limitations, consider serializing complex data types into strings using JSON serialization.

- **Example:**

  ```python
  import json
  from configconverter import convert

  # Serialize complex data to JSON strings before conversion
  def serialize_complex_data(data):
      if isinstance(data, (dict, list)):
          return json.dumps(data)
      return data

  # Custom converter function
  def custom_convert(input_file, output_file):
      with open(input_file, 'r') as f:
          data = json.load(f)

      # Serialize complex data
      for key, value in data.items():
          data[key] = serialize_complex_data(value)

      # Convert to INI
      convert(data, 'json', 'ini', output_file=output_file, from_file=False)

  custom_convert('complex_config.json', 'config.ini')


## Limitations and Known Issues

While ConfigConverter is designed to handle a wide range of configuration files, there are some limitations due to inherent differences between configuration formats:

- **Format Incompatibilities:**

  - **INI Format Limitations:**
    - *No Nested Structures:* INI files do not support nested sections or hierarchical data.
    - *All Values are Strings:* INI treats all values as strings, lacking native support for integers, booleans, or lists.
    - *Loss of Hierarchy:* Nested data from formats like JSON, YAML, or TOML may be flattened when converted to INI, leading to potential loss of context.

  - **XML Format Limitations:**
    - *Complex Representation:* XML can represent nested structures but may not handle data types like booleans or integers without additional schema definitions.
    - *Attributes vs. Elements:* Differentiating between attributes and elements can complicate the parsing and emitting processes.

## Detailed Documentation

For comprehensive guides, advanced usage, and API references, visit the [ConfigConverter Documentation](https://ankit-aglawe.github.io/configconverter/).

- **Usage Guidelines:** Best practices for using ConfigConverter effectively.
- **Handling Complex Data:** Strategies for dealing with nested structures and special data types.
- **Error Handling:** Information on error messages and logging to help you troubleshoot issues.
- **Examples:** Additional examples demonstrating various conversion scenarios and edge cases.

## Examples

### Batch Conversion

Convert all JSON files in a directory to YAML:

```python
import os
from configconverter import convert

input_dir = 'json_configs'
output_dir = 'yaml_configs'
os.makedirs(output_dir, exist_ok=True)

for filename in os.listdir(input_dir):
    if filename.endswith('.json'):
        input_file = os.path.join(input_dir, filename)
        output_file = os.path.join(output_dir, filename.replace('.json', '.yaml'))
        convert(input_file, 'json', 'yaml', output_file=output_file)
```


## Contributing

Contributions are welcome! Whether it's reporting a bug, suggesting a feature, or submitting a pull request, your help is greatly appreciated.

1. **Fork the Repository**
2. **Create a Feature Branch**

   ```bash
   git checkout -b feature/your-feature-name
   ```

3. **Commit Your Changes**

   ```bash
   git commit -m "Add awesome feature"
   ```

4. **Push to the Branch**

   ```bash
   git push origin feature/your-feature-name
   ```

5. **Open a Pull Request**

For more detailed guidelines, refer to the [Contributing Guide](https://github.com/ankit-aglawe/configconverter/blob/main/docs/contributing.md).

## License

This project is licensed under the [MIT License](https://github.com/ankit-aglawe/configconverter/blob/main/LICENSE).

## Contact

- **Author:** Ankit Aglawe
- **Email:** [aglawe.ankit@gmail.com](mailto:aglawe.ankit@gmail.com)
- **GitHub:** [ankit-aglawe](https://github.com/ankit-aglawe)
- **Documentation:** [ConfigConverter Docs](https://ankit-aglawe.github.io/configconverter/)
- **PyPI:** [configconverter](https://pypi.org/project/configconverter/)

## Useful Links

- [Project Repository](https://github.com/ankit-aglawe/configconverter)
- [PyPI Package](https://pypi.org/project/configconverter/)
- [Documentation](https://ankit-aglawe.github.io/configconverter/)
- [Issue Tracker](https://github.com/ankit-aglawe/configconverter/issues)



            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/ankitaglawe/configconverter",
    "name": "configconverter",
    "maintainer": null,
    "docs_url": null,
    "requires_python": "<4.0,>=3.8",
    "maintainer_email": null,
    "keywords": "configuration, converter, json, yaml, toml, ini, xml",
    "author": "Ankit Aglawe",
    "author_email": "aglawe.ankit@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/c4/b4/cd91a1d09a2e8a71878fb584a4bc7fced05f0b4bc117403feb43f9557071/configconverter-0.3.0.tar.gz",
    "platform": null,
    "description": "# ConfigConverter\n\n[![PyPI Version](https://img.shields.io/pypi/v/configconverter.svg)](https://pypi.org/project/configconverter/)\n[![Python Versions](https://img.shields.io/pypi/pyversions/configconverter.svg)](https://pypi.org/project/configconverter/)\n[![License](https://img.shields.io/pypi/l/configconverter.svg)](https://github.com/ankit-aglawe/configconverter/blob/main/LICENSE)\n[![Documentation](https://img.shields.io/badge/docs-available-brightgreen.svg)](https://ankit-aglawe.github.io/configconverter/)\n\n**ConfigConverter** is a powerful and easy-to-use tool designed to convert configuration files between various formats, including JSON, YAML, TOML, INI, and XML. \n\n## Features\n\n- **Multi-Format Support:** Seamlessly convert between JSON, YAML, TOML, INI, and XML formats.\n- **Command-Line Interface (CLI):** Perform conversions directly from your terminal with simple commands.\n- **Python API:** Integrate conversion functionality into your Python projects effortlessly.\n- **Extensible and Customizable:** Easily extend the tool to support additional formats or custom conversion logic.\n- **User-Friendly:** Intuitive design ensures a smooth experience for both beginners and advanced users.\n\n## Installation\n\n### Via PyPI\n\nInstall ConfigConverter using `pip`:\n\n```bash\npip install configconverter\n```\n\n### From Source\n\nClone the repository and install using Poetry:\n\n```bash\ngit clone https://github.com/ankit-aglawe/configconverter.git\ncd configconverter\npoetry install\n```\n\n## Quick Start\n\n### Command-Line Usage\n\nConvert `config.json` to `config.yaml`:\n\n```bash\nconfigconverter config.json config.yaml\n```\n\nSpecify input and output formats explicitly:\n\n```bash\nconfigconverter -i ini -o toml settings.conf settings.toml\n```\n\nOutput the converted configuration to standard output:\n\n```bash\nconfigconverter config.toml -o json --stdout\n```\n\n### Python API Usage\n\n#### Convert Using File Paths\n\n```python\nfrom configconverter import convert\n\n# Convert JSON to YAML and save to a file\nconvert('config.json', 'json', 'yaml', output_file='config.yaml')\n```\n\n#### Convert Using Data Strings\n\n```python\nfrom configconverter import convert\n\n# Convert JSON string to YAML string\njson_data = '{\"name\": \"John\", \"age\": 30}'\nyaml_data = convert(json_data, 'json', 'yaml', from_file=False)\nprint(yaml_data)\n```\n\n## Detailed Documentation\n\nFor comprehensive guides, advanced usage, and API references, visit the [ConfigConverter Documentation](https://ankit-aglawe.github.io/configconverter/).\n\n## Examples\n\n### Batch Conversion\n\nConvert all JSON files in a directory to YAML:\n\n```python\nimport os\nfrom configconverter import convert\n\ninput_dir = 'json_configs'\noutput_dir = 'yaml_configs'\nos.makedirs(output_dir, exist_ok=True)\n\nfor filename in os.listdir(input_dir):\n    if filename.endswith('.json'):\n        input_file = os.path.join(input_dir, filename)\n        output_file = os.path.join(output_dir, filename.replace('.json', '.yaml'))\n        convert(input_file, 'json', 'yaml', output_file=output_file)\n```\n\n### Custom Indentation\n\nConvert a file with custom indentation:\n\n```bash\nconfigconverter config.json config.yaml --indent 2\n```\n### Handling Complex Data Structures\n\nWhen dealing with configurations that contain complex nested structures or special data types, consider the following:\n\n- **Avoid Incompatible Formats:** As INI format does not support nested structures, avoid converting complex configurations to INI.\n\n- **Custom Serialization:** If you must convert to a format with limitations, consider serializing complex data types into strings using JSON serialization.\n\n- **Example:**\n\n  ```python\n  import json\n  from configconverter import convert\n\n  # Serialize complex data to JSON strings before conversion\n  def serialize_complex_data(data):\n      if isinstance(data, (dict, list)):\n          return json.dumps(data)\n      return data\n\n  # Custom converter function\n  def custom_convert(input_file, output_file):\n      with open(input_file, 'r') as f:\n          data = json.load(f)\n\n      # Serialize complex data\n      for key, value in data.items():\n          data[key] = serialize_complex_data(value)\n\n      # Convert to INI\n      convert(data, 'json', 'ini', output_file=output_file, from_file=False)\n\n  custom_convert('complex_config.json', 'config.ini')\n\n\n## Limitations and Known Issues\n\nWhile ConfigConverter is designed to handle a wide range of configuration files, there are some limitations due to inherent differences between configuration formats:\n\n- **Format Incompatibilities:**\n\n  - **INI Format Limitations:**\n    - *No Nested Structures:* INI files do not support nested sections or hierarchical data.\n    - *All Values are Strings:* INI treats all values as strings, lacking native support for integers, booleans, or lists.\n    - *Loss of Hierarchy:* Nested data from formats like JSON, YAML, or TOML may be flattened when converted to INI, leading to potential loss of context.\n\n  - **XML Format Limitations:**\n    - *Complex Representation:* XML can represent nested structures but may not handle data types like booleans or integers without additional schema definitions.\n    - *Attributes vs. Elements:* Differentiating between attributes and elements can complicate the parsing and emitting processes.\n\n## Detailed Documentation\n\nFor comprehensive guides, advanced usage, and API references, visit the [ConfigConverter Documentation](https://ankit-aglawe.github.io/configconverter/).\n\n- **Usage Guidelines:** Best practices for using ConfigConverter effectively.\n- **Handling Complex Data:** Strategies for dealing with nested structures and special data types.\n- **Error Handling:** Information on error messages and logging to help you troubleshoot issues.\n- **Examples:** Additional examples demonstrating various conversion scenarios and edge cases.\n\n## Examples\n\n### Batch Conversion\n\nConvert all JSON files in a directory to YAML:\n\n```python\nimport os\nfrom configconverter import convert\n\ninput_dir = 'json_configs'\noutput_dir = 'yaml_configs'\nos.makedirs(output_dir, exist_ok=True)\n\nfor filename in os.listdir(input_dir):\n    if filename.endswith('.json'):\n        input_file = os.path.join(input_dir, filename)\n        output_file = os.path.join(output_dir, filename.replace('.json', '.yaml'))\n        convert(input_file, 'json', 'yaml', output_file=output_file)\n```\n\n\n## Contributing\n\nContributions are welcome! Whether it's reporting a bug, suggesting a feature, or submitting a pull request, your help is greatly appreciated.\n\n1. **Fork the Repository**\n2. **Create a Feature Branch**\n\n   ```bash\n   git checkout -b feature/your-feature-name\n   ```\n\n3. **Commit Your Changes**\n\n   ```bash\n   git commit -m \"Add awesome feature\"\n   ```\n\n4. **Push to the Branch**\n\n   ```bash\n   git push origin feature/your-feature-name\n   ```\n\n5. **Open a Pull Request**\n\nFor more detailed guidelines, refer to the [Contributing Guide](https://github.com/ankit-aglawe/configconverter/blob/main/docs/contributing.md).\n\n## License\n\nThis project is licensed under the [MIT License](https://github.com/ankit-aglawe/configconverter/blob/main/LICENSE).\n\n## Contact\n\n- **Author:** Ankit Aglawe\n- **Email:** [aglawe.ankit@gmail.com](mailto:aglawe.ankit@gmail.com)\n- **GitHub:** [ankit-aglawe](https://github.com/ankit-aglawe)\n- **Documentation:** [ConfigConverter Docs](https://ankit-aglawe.github.io/configconverter/)\n- **PyPI:** [configconverter](https://pypi.org/project/configconverter/)\n\n## Useful Links\n\n- [Project Repository](https://github.com/ankit-aglawe/configconverter)\n- [PyPI Package](https://pypi.org/project/configconverter/)\n- [Documentation](https://ankit-aglawe.github.io/configconverter/)\n- [Issue Tracker](https://github.com/ankit-aglawe/configconverter/issues)\n\n\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "A versatile tool to convert configuration files between different formats.",
    "version": "0.3.0",
    "project_urls": {
        "Documentation": "https://configconverter.readthedocs.io",
        "Homepage": "https://github.com/ankitaglawe/configconverter",
        "Repository": "https://github.com/ankitaglawe/configconverter"
    },
    "split_keywords": [
        "configuration",
        " converter",
        " json",
        " yaml",
        " toml",
        " ini",
        " xml"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "ab11cb9b5555d82b03c27a291fd14b87f8382d53360d0ffa9cb148cf8b8ad02e",
                "md5": "7819bbb20a53f21235ac01d908ee4d15",
                "sha256": "8b68b35e116f8a26cf545eab751c3ad9c2fa856d3ab2b9fc7631558b2fb7f06d"
            },
            "downloads": -1,
            "filename": "configconverter-0.3.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "7819bbb20a53f21235ac01d908ee4d15",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": "<4.0,>=3.8",
            "size": 10542,
            "upload_time": "2024-10-09T09:08:28",
            "upload_time_iso_8601": "2024-10-09T09:08:28.766333Z",
            "url": "https://files.pythonhosted.org/packages/ab/11/cb9b5555d82b03c27a291fd14b87f8382d53360d0ffa9cb148cf8b8ad02e/configconverter-0.3.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "c4b4cd91a1d09a2e8a71878fb584a4bc7fced05f0b4bc117403feb43f9557071",
                "md5": "0a742c690a7b84c6c00b2d2e22258504",
                "sha256": "e49f0eb8a5eb72713a8d3d26d4ac9c7e28c459eb5615c11e0b0db5ecdbf1e4c6"
            },
            "downloads": -1,
            "filename": "configconverter-0.3.0.tar.gz",
            "has_sig": false,
            "md5_digest": "0a742c690a7b84c6c00b2d2e22258504",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": "<4.0,>=3.8",
            "size": 10279,
            "upload_time": "2024-10-09T09:08:30",
            "upload_time_iso_8601": "2024-10-09T09:08:30.697751Z",
            "url": "https://files.pythonhosted.org/packages/c4/b4/cd91a1d09a2e8a71878fb584a4bc7fced05f0b4bc117403feb43f9557071/configconverter-0.3.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-10-09 09:08:30",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "ankitaglawe",
    "github_project": "configconverter",
    "github_not_found": true,
    "lcname": "configconverter"
}
        
Elapsed time: 1.14445s