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
Setup API Key (Recommended)
Export your OpenAI API key as an environment variable:
export VIBE_PP_API_KEY="your-openai-api-key-here"
Then use the library without hardcoding your API key:
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):
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 useVIBE_PP_API_KEYenvironment variable.
Returns:
str: Pretty-printed/formatted string
Raises:
ValidationError: If the input format is invalidOpenAIError: If OpenAI API calls failValueError: 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(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
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
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
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:
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
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
- Fork the repository
- Create a feature branch
- Make your changes
- Add tests
- Run the test suite
- Submit a pull request
Support
For issues and questions, please use the GitHub Issues page.
Metadata
Release files for vibe-pretty-print 0.1.3
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| vibe_pretty_print-0.1.3.tar.gz | 10.2 kB | Without provenance | Details for vibe_pretty_print-0.1.3.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| vibe_pretty_print-0.1.3-py3-none-any.whl | Python 3 | none | any | Details for vibe_pretty_print-0.1.3-py3-none-any.whl |
Total release size: 18.6 kB
Release files / vibe_pretty_print-0.1.3.tar.gz
| Download URL | vibe_pretty_print-0.1.3.tar.gz |
|---|---|
| Size | 10.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
97b1e31623e7a8cae6d436d6f1ab31d76c76ead7ba94d1104c15140697dea394
|
|
BLAKE2b-256 checksum How to use checksums |
6b73c1bbda0c9207c4c94c5b238cc8d64480e8802dcb821e8a23c301a285a3f1
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.11.8
|
Release files / vibe_pretty_print-0.1.3-py3-none-any.whl
| Download URL | vibe_pretty_print-0.1.3-py3-none-any.whl |
|---|---|
| Size | 8.5 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
6eb99acfe187005ba4011447731947bf2d6488bb9bba6fd43fe8c831b61cb348
|
|
BLAKE2b-256 checksum How to use checksums |
1c1de47609f1f1b00050582982ad72abf3c56032b3f2fc50842ebbf45bc72162
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.11.8
|
Security for vibe-pretty-print 0.1.3
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.