vibe-pretty-print


Namevibe-pretty-print JSON
Version 0.1.3 PyPI version JSON
download
home_pageNone
SummaryA smart formatting library for JSON, XML, YAML, and text with OpenAI integration
upload_time2025-08-24 03:16:40
maintainerNone
docs_urlNone
authorNone
requires_python>=3.7
licenseNone
keywords pretty-print json xml yaml formatting openai
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # vibe-pretty-print

A smart Python library for formatting JSON, XML, YAML, and plain text with OpenAI-powered enhancement.

## Features

- **Multi-format support**: JSON, XML, YAML, and plain text formatting
- **Validation**: Validates JSON, XML, and YAML before formatting
- **OpenAI integration**: Uses OpenAI GPT for enhanced formatting and readability
- **Color output**: Provides colored output for better readability
- **Fallback handling**: Gracefully falls back to standard formatting if OpenAI fails
- **Type-safe**: Full type hints and error handling

## Installation

```bash
pip install vibe-pretty-print
```

## Quick Start

### Setup API Key (Recommended)

Export your OpenAI API key as an environment variable:

```bash
export VIBE_PP_API_KEY="your-openai-api-key-here"
```

Then use the library without hardcoding your API key:

```python
from vibe_pprint import vibe_pprint

# Format JSON
json_text = '{"name":"John","age":30,"city":"New York"}'
formatted_json = vibe_pprint(text=json_text, format_type="json")
print(formatted_json)

# Format YAML
yaml_text = "name: John\nage: 30\ncity: New York"
formatted_yaml = vibe_pprint(text=yaml_text, format_type="yaml")
print(formatted_yaml)

# Format XML
xml_text = "<person><name>John</name><age>30</age></person>"
formatted_xml = vibe_pprint(text=xml_text, format_type="xml")
print(formatted_xml)

# Format plain text
text = "Hello World! This is a test."
formatted_text = vibe_pprint(text=text, format_type="text")
print(formatted_text)
```

### Alternative: Hardcoded API Key (Not Recommended)

If you prefer, you can still pass the API key directly (less secure):

```python
from vibe_pprint import vibe_pprint

# Only use this approach for quick testing
formatted = vibe_pprint(
    api_key="your-openai-api-key", 
    text='{"test": "data"}', 
    format_type="json"
)
```

## API Reference

### `vibe_pprint(text, format_type="text", api_key=None)`

**Parameters:**
- `text` (str): The content to format (JSON, XML, YAML, or plain text)
- `format_type` (str): Type of content - `"json"`, `"xml"`, `"yaml"`, or `"text"` (default: `"text"`)
- `api_key` (str, optional): Your OpenAI API key. If not provided, will use `VIBE_PP_API_KEY` environment variable.

**Returns:**
- `str`: Pretty-printed/formatted string

**Raises:**
- `ValidationError`: If the input format is invalid
- `OpenAIError`: If OpenAI API calls fail
- `ValueError`: If format_type is invalid or inputs are empty

## Usage Examples

### JSON Formatting

```python
from vibe_pprint import vibe_pprint

# Valid JSON
json_data = '{"users":[{"name":"Alice","age":25},{"name":"Bob","age":30}]}'
result = vibe_pprint(json_data, "json")
print(result)
# Output:
# {
#   "users": [
#     {
#       "age": 25,
#       "name": "Alice"
#     },
#     {
#       "age": 30,
#       "name": "Bob"
#     }
#   ]
# }

# Invalid JSON - will raise ValidationError
try:
    vibe_pprint('{"invalid": json}', "json")
except ValidationError as e:
    print(f"JSON validation failed: {e}")
```

### YAML Formatting

```python
yaml_data = """
users:
  - name: Alice
    age: 25
    skills:
      - Python
      - JavaScript
  - name: Bob
    age: 30
    skills:
      - Java
      - SQL
"""
result = vibe_pprint(yaml_data, "yaml")
print(result)
```

### XML Formatting

```python
xml_data = "<book><title>Python Guide</title><author>John Doe</author><year>2024</year></book>"
result = vibe_pprint(xml_data, "xml")
print(result)
```

### Plain Text Formatting

```python
text = "# Configuration\nhost: localhost\nport: 8080\nurl: https://example.com"
result = vibe_pprint(text, "text")
print(result)
# Output with color highlighting for comments, URLs, and numbers
```

## Error Handling

The library provides specific exceptions for different error scenarios:

```python
from vibe_pprint import ValidationError, OpenAIError

try:
    result = vibe_pprint(invalid_json, "json")
except ValidationError as e:
    print(f"Input validation failed: {e}")
except OpenAIError as e:
    print(f"OpenAI API error: {e}")
except ValueError as e:
    print(f"Invalid input: {e}")
```

## Requirements

- Python 3.7+
- requests
- PyYAML
- colorama
- lxml

## Development

### Install development dependencies

```bash
pip install -e ".[dev]"
```

### Run tests

```bash
pytest
```

### Code formatting

```bash
black vibe_pprint/
```

### Type checking

```bash
mypy vibe_pprint/
```

## License

MIT License - see LICENSE file for details.

## Contributing

1. Fork the repository
2. Create a feature branch
3. Make your changes
4. Add tests
5. Run the test suite
6. Submit a pull request

## Support

For issues and questions, please use the [GitHub Issues](https://github.com/yourusername/vibe-pretty-print/issues) page.

            

Raw data

            {
    "_id": null,
    "home_page": null,
    "name": "vibe-pretty-print",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.7",
    "maintainer_email": null,
    "keywords": "pretty-print, json, xml, yaml, formatting, openai",
    "author": null,
    "author_email": "Khanh Ngo <akatekhanh0212@gmail.com>",
    "download_url": "https://files.pythonhosted.org/packages/6b/73/c1bbda0c9207c4c94c5b238cc8d64480e8802dcb821e8a23c301a285a3f1/vibe_pretty_print-0.1.3.tar.gz",
    "platform": null,
    "description": "# vibe-pretty-print\n\nA smart Python library for formatting JSON, XML, YAML, and plain text with OpenAI-powered enhancement.\n\n## Features\n\n- **Multi-format support**: JSON, XML, YAML, and plain text formatting\n- **Validation**: Validates JSON, XML, and YAML before formatting\n- **OpenAI integration**: Uses OpenAI GPT for enhanced formatting and readability\n- **Color output**: Provides colored output for better readability\n- **Fallback handling**: Gracefully falls back to standard formatting if OpenAI fails\n- **Type-safe**: Full type hints and error handling\n\n## Installation\n\n```bash\npip install vibe-pretty-print\n```\n\n## Quick Start\n\n### Setup API Key (Recommended)\n\nExport your OpenAI API key as an environment variable:\n\n```bash\nexport VIBE_PP_API_KEY=\"your-openai-api-key-here\"\n```\n\nThen use the library without hardcoding your API key:\n\n```python\nfrom vibe_pprint import vibe_pprint\n\n# Format JSON\njson_text = '{\"name\":\"John\",\"age\":30,\"city\":\"New York\"}'\nformatted_json = vibe_pprint(text=json_text, format_type=\"json\")\nprint(formatted_json)\n\n# Format YAML\nyaml_text = \"name: John\\nage: 30\\ncity: New York\"\nformatted_yaml = vibe_pprint(text=yaml_text, format_type=\"yaml\")\nprint(formatted_yaml)\n\n# Format XML\nxml_text = \"<person><name>John</name><age>30</age></person>\"\nformatted_xml = vibe_pprint(text=xml_text, format_type=\"xml\")\nprint(formatted_xml)\n\n# Format plain text\ntext = \"Hello World! This is a test.\"\nformatted_text = vibe_pprint(text=text, format_type=\"text\")\nprint(formatted_text)\n```\n\n### Alternative: Hardcoded API Key (Not Recommended)\n\nIf you prefer, you can still pass the API key directly (less secure):\n\n```python\nfrom vibe_pprint import vibe_pprint\n\n# Only use this approach for quick testing\nformatted = vibe_pprint(\n    api_key=\"your-openai-api-key\", \n    text='{\"test\": \"data\"}', \n    format_type=\"json\"\n)\n```\n\n## API Reference\n\n### `vibe_pprint(text, format_type=\"text\", api_key=None)`\n\n**Parameters:**\n- `text` (str): The content to format (JSON, XML, YAML, or plain text)\n- `format_type` (str): Type of content - `\"json\"`, `\"xml\"`, `\"yaml\"`, or `\"text\"` (default: `\"text\"`)\n- `api_key` (str, optional): Your OpenAI API key. If not provided, will use `VIBE_PP_API_KEY` environment variable.\n\n**Returns:**\n- `str`: Pretty-printed/formatted string\n\n**Raises:**\n- `ValidationError`: If the input format is invalid\n- `OpenAIError`: If OpenAI API calls fail\n- `ValueError`: If format_type is invalid or inputs are empty\n\n## Usage Examples\n\n### JSON Formatting\n\n```python\nfrom vibe_pprint import vibe_pprint\n\n# Valid JSON\njson_data = '{\"users\":[{\"name\":\"Alice\",\"age\":25},{\"name\":\"Bob\",\"age\":30}]}'\nresult = vibe_pprint(json_data, \"json\")\nprint(result)\n# Output:\n# {\n#   \"users\": [\n#     {\n#       \"age\": 25,\n#       \"name\": \"Alice\"\n#     },\n#     {\n#       \"age\": 30,\n#       \"name\": \"Bob\"\n#     }\n#   ]\n# }\n\n# Invalid JSON - will raise ValidationError\ntry:\n    vibe_pprint('{\"invalid\": json}', \"json\")\nexcept ValidationError as e:\n    print(f\"JSON validation failed: {e}\")\n```\n\n### YAML Formatting\n\n```python\nyaml_data = \"\"\"\nusers:\n  - name: Alice\n    age: 25\n    skills:\n      - Python\n      - JavaScript\n  - name: Bob\n    age: 30\n    skills:\n      - Java\n      - SQL\n\"\"\"\nresult = vibe_pprint(yaml_data, \"yaml\")\nprint(result)\n```\n\n### XML Formatting\n\n```python\nxml_data = \"<book><title>Python Guide</title><author>John Doe</author><year>2024</year></book>\"\nresult = vibe_pprint(xml_data, \"xml\")\nprint(result)\n```\n\n### Plain Text Formatting\n\n```python\ntext = \"# Configuration\\nhost: localhost\\nport: 8080\\nurl: https://example.com\"\nresult = vibe_pprint(text, \"text\")\nprint(result)\n# Output with color highlighting for comments, URLs, and numbers\n```\n\n## Error Handling\n\nThe library provides specific exceptions for different error scenarios:\n\n```python\nfrom vibe_pprint import ValidationError, OpenAIError\n\ntry:\n    result = vibe_pprint(invalid_json, \"json\")\nexcept ValidationError as e:\n    print(f\"Input validation failed: {e}\")\nexcept OpenAIError as e:\n    print(f\"OpenAI API error: {e}\")\nexcept ValueError as e:\n    print(f\"Invalid input: {e}\")\n```\n\n## Requirements\n\n- Python 3.7+\n- requests\n- PyYAML\n- colorama\n- lxml\n\n## Development\n\n### Install development dependencies\n\n```bash\npip install -e \".[dev]\"\n```\n\n### Run tests\n\n```bash\npytest\n```\n\n### Code formatting\n\n```bash\nblack vibe_pprint/\n```\n\n### Type checking\n\n```bash\nmypy vibe_pprint/\n```\n\n## License\n\nMIT License - see LICENSE file for details.\n\n## Contributing\n\n1. Fork the repository\n2. Create a feature branch\n3. Make your changes\n4. Add tests\n5. Run the test suite\n6. Submit a pull request\n\n## Support\n\nFor issues and questions, please use the [GitHub Issues](https://github.com/yourusername/vibe-pretty-print/issues) page.\n",
    "bugtrack_url": null,
    "license": null,
    "summary": "A smart formatting library for JSON, XML, YAML, and text with OpenAI integration",
    "version": "0.1.3",
    "project_urls": {
        "Homepage": "https://github.com/akatekhanh/vibe-pretty-print",
        "Issues": "https://github.com/akatekhanh/vibe-pretty-print/issues",
        "Repository": "https://github.com/akatekhanh/vibe-pretty-print"
    },
    "split_keywords": [
        "pretty-print",
        " json",
        " xml",
        " yaml",
        " formatting",
        " openai"
    ],
    "urls": [
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "1c1de47609f1f1b00050582982ad72abf3c56032b3f2fc50842ebbf45bc72162",
                "md5": "e93c85317f20892c08fbec90daed605d",
                "sha256": "6eb99acfe187005ba4011447731947bf2d6488bb9bba6fd43fe8c831b61cb348"
            },
            "downloads": -1,
            "filename": "vibe_pretty_print-0.1.3-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "e93c85317f20892c08fbec90daed605d",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.7",
            "size": 8451,
            "upload_time": "2025-08-24T03:16:39",
            "upload_time_iso_8601": "2025-08-24T03:16:39.610656Z",
            "url": "https://files.pythonhosted.org/packages/1c/1d/e47609f1f1b00050582982ad72abf3c56032b3f2fc50842ebbf45bc72162/vibe_pretty_print-0.1.3-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "6b73c1bbda0c9207c4c94c5b238cc8d64480e8802dcb821e8a23c301a285a3f1",
                "md5": "bdedda193275cb29ad55a8f162e2d7b0",
                "sha256": "97b1e31623e7a8cae6d436d6f1ab31d76c76ead7ba94d1104c15140697dea394"
            },
            "downloads": -1,
            "filename": "vibe_pretty_print-0.1.3.tar.gz",
            "has_sig": false,
            "md5_digest": "bdedda193275cb29ad55a8f162e2d7b0",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.7",
            "size": 10188,
            "upload_time": "2025-08-24T03:16:40",
            "upload_time_iso_8601": "2025-08-24T03:16:40.664267Z",
            "url": "https://files.pythonhosted.org/packages/6b/73/c1bbda0c9207c4c94c5b238cc8d64480e8802dcb821e8a23c301a285a3f1/vibe_pretty_print-0.1.3.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2025-08-24 03:16:40",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "akatekhanh",
    "github_project": "vibe-pretty-print",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "lcname": "vibe-pretty-print"
}
        
Elapsed time: 1.30002s