Skip to main content

A smart formatting library for JSON, XML, YAML, and text with OpenAI integration

Project description

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

pip install vibe-pretty-print

Quick Start

from vibe_pprint import vibe_pprint

# Format JSON
json_text = '{"name":"John","age":30,"city":"New York"}'
formatted_json = vibe_pprint("your-openai-api-key", json_text, "json")
print(formatted_json)

# Format YAML
yaml_text = "name: John\nage: 30\ncity: New York"
formatted_yaml = vibe_pprint("your-openai-api-key", yaml_text, "yaml")
print(formatted_yaml)

# Format XML
xml_text = "<person><name>John</name><age>30</age></person>"
formatted_xml = vibe_pprint("your-openai-api-key", xml_text, "xml")
print(formatted_xml)

# Format plain text
text = "Hello World! This is a test."
formatted_text = vibe_pprint("your-openai-api-key", text, "text")
print(formatted_text)

API Reference

vibe_pprint(api_key, text, format_type="text")

Parameters:

  • api_key (str): Your OpenAI API key for enhanced formatting
  • 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")

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

from vibe_pprint import vibe_pprint

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

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

YAML Formatting

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

XML Formatting

xml_data = "<book><title>Python Guide</title><author>John Doe</author><year>2024</year></book>"
result = vibe_pprint("your-api-key", xml_data, "xml")
print(result)

Plain Text Formatting

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

Error Handling

The library provides specific exceptions for different error scenarios:

from vibe_pprint import ValidationError, OpenAIError

try:
    result = vibe_pprint("your-api-key", 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

pip install -e ".[dev]"

Run tests

pytest

Code formatting

black vibe_pprint/

Type checking

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 page.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

vibe_pretty_print-0.1.0.tar.gz (10.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

vibe_pretty_print-0.1.0-py3-none-any.whl (7.3 kB view details)

Uploaded Python 3

File details

Details for the file vibe_pretty_print-0.1.0.tar.gz.

File metadata

  • Download URL: vibe_pretty_print-0.1.0.tar.gz
  • Upload date:
  • Size: 10.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.11.8

File hashes

Hashes for vibe_pretty_print-0.1.0.tar.gz
Algorithm Hash digest
SHA256 fd987d1f0cf54fc761be43c8a36aaf7c383f961890a6896a4b2e0abf5401a30b
MD5 690a5abd4d21e6dbbbf9db63e9e5233a
BLAKE2b-256 7bb926fc9685e48c05c10b3b133cdb6cd4d8a166f05c17a29aab7268bf70688b

See more details on using hashes here.

File details

Details for the file vibe_pretty_print-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for vibe_pretty_print-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 5b99ec8fd20cc365a22510cf8e04ea7ab0bb0358c90c3720a99a47726b95938a
MD5 7510c9b3232e4f06ded5f91ae9652d0a
BLAKE2b-256 2f927a81287d0ea14d95fd255ae9132ffec158a672aaa2b415a605c77b347fa6

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page