🚀 Your toolkit for seamless JSON handling in Python 🐍
Overview •
Features •
Installation •
Usage •
License •
Contributing
Overview
JSONKit is a Python Library for enhanced JSON file handling with support for datetime
and UUID
objects. It provides both synchronous
and asynchronous
file operations.
Features
-
Synchronous Operations: Read and write JSON files with custom encoding and decoding for datetime
and UUID
objects.
-
Asynchronous Operations: Handle JSON files asynchronously using aiofiles
.
-
Custom Serialization: Special handling for datetime
and UUID
types.
-
Pretty Printing: Pretty printing powered by the rich library!
Installation
You can install JSONKit via pip:
pip install py-jsonkit
Usage
👉 Loading JSON from a File
You can load a JSON file into a Python object easily:
from jsonkit import JSONFile
json_file = JSONFile('example.json')
data = json_file.load()
👉 Writing data to a JSON file:
You can also write some data to a JSONFile easily
from jsonkit import JSONFile
from datetime import datetime
import uuid
json_file = JSONFile('example.json')
data_to_write = {
"name": "Alice",
"age": 30,
"created_at": datetime.now(),
"uid": uuid.uuid4()
}
new_returned_data = json_file.write(data_to_write, indent=4)
json_file.write(data_to_write, indent=4)
new_data = json_file.load()
data = json_file.load()
data["......"] = "......"
data["woah this is some new data"] = "I am the value of the new data!"
json_file.write(data, indent=4)
👉 Pretty Printing
JSONKit also comes with pretty printing which is handled by the rich library!
from jsonkit import JSONFile
json_file = JSONFile('example.json')
json_file.print_data()
👉 Asynchronous Support
JSONKit can also be used asynchronously using the AsyncJSONFile
class!
from jsonkit import AsyncJSONFile
import asyncio
async_json_file = AsyncJSONFile('example.json')
async def main():
data = await async_json_file.load()
data_to_insert = {
"...": "..."
}
await async_json_file.write(data_to_insert, indent=4)
await async_json_file.print_data()
asyncio.run(main())
License
JSONKit is licensed under the MIT License. See the LICENSE file for more details.
Contributing
Contributions are welcome! Please open an issue or submit a pull request.