A python implementation of the JsonCanvas format: https://github.com/obsidianmd/jsoncanvas/blob/main/spec/1.0.md
Project description
JsonCanvas Python Implementation
This project provides a Python implementation of the JsonCanvas format, designed to enable the creation, manipulation, and serialization of a structured canvas representation. It is built using Python's dataclasses
for easy data management and supports various node types including Text, File, Link, Group, and Edge elements.
Features
- Define and manipulate canvas elements like Nodes and Edges.
- Serialize and deserialize canvas data to and from JSON.
- Easy integration with file systems for reading and writing canvas data.
Installation
pip install openjsoncanvas
Usage
Creating a Canvas
You can create a canvas programmatically by adding nodes and edges:
from openjsoncanvas import Canvas, TextNode, LinkNode, Edge
# Create a new canvas
canvas = Canvas()
# Add nodes
canvas.add_node(TextNode(id='1', x=100, y=100, width=200, height=100, text='Hello World'))
canvas.add_node(LinkNode(id='2', x=300, y=100, width=200, height=100, url='https://example.com'))
# Add an edge
canvas.add_edge(Edge(id='1', fromNode='1', toNode='2'))
# Serialize to JSON
json_output = canvas.to_json()
print(json_output)
# Write to file
canvas.to_file('example.canvas')
Loading from JSON
You can load a canvas from a JSON string or file:
# Load from JSON string
json_str = '{"nodes": [{"id": "1", "type": "text", "x": 100, "y": 100, "width": 200, "height": 100, "text": "Hello World"}]}'
loaded_canvas = Canvas.from_json(json_str)
# Load from a file
loaded_canvas = Canvas.from_file('path_to_your_canvas_file.canvas')
Contributing
Contributions are welcome! Feel free to open issues or submit pull requests to our repository.
License
This project is licensed under the MIT License - see the LICENSE file for details.
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
Built Distribution
Hashes for openjsoncanvas-2.0.0-py2.py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b33154ee7a467bba26e89e01911b6a41083dd5c31047e1c070dd51854ac50028 |
|
MD5 | 24580e93011dcacb247f0033a1bda9e0 |
|
BLAKE2b-256 | 7af1bdf1841f789dd2d76b8c5c28af8af21c516fa9248544b5da74cd3fbe6d65 |