PyJSONCanvas
PyJSONCanvas is a Python library for working with JSON Canvas (previously known as Obsidian Canvas) files. It provides a simple and intuitive API for creating, editing, and manipulating canvas objects, nodes, and edges.
Features
- Create, load, and save canvas files in JSON format
- Add, remove, and modify nodes (text, file, link, group)
- Add, remove, and modify edges with various styles and colors
- Validate canvas, nodes, and edges for integrity
- Get connections and adjacent nodes for a given node
- Extensive error handling and helpful exception messages
Installation
You can install PyJSONCanvas using pip:
pip install PyJSONCanvas
Usage
Here's a basic example of how to use PyJSONCanvas:
from pyjsoncanvas import (
Canvas,
TextNode,
FileNode,
LinkNode,
GroupNode,
GroupNodeBackgroundStyle,
Edge,
Color,
)
canvas = Canvas(nodes=[], edges=[])
text_node = TextNode(x=100, y=100, width=200, height=100, text="Hello, world!")
canvas.add_node(text_node)
file_node = FileNode(x=300, y=100, width=100, height=100, file="/path/to/file.png")
canvas.add_node(file_node)
edge = Edge(
fromNode=text_node.id,
fromSide="bottom",
toNode=file_node.id,
toSide="top",
color=Color("#FF0000"),
label="Edge 1",
)
canvas.add_edge(edge)
json_str = canvas.to_json()
loaded_canvas = Canvas.from_json(json_str)
node = loaded_canvas.get_node(text_node.id)
connections = loaded_canvas.get_connections(text_node.id)
Documentation
The PyJSONCanvas library is well-documented, and you can find detailed information about all the available classes, methods, and exceptions in the docstrings and code comments.
Contributing
We welcome contributions to PyJSONCanvas! If you find any issues or have suggestions for improvements, please open an issue or submit a pull request on the GitHub repository.
License
PyJSONCanvas is released under the MIT License.
Support
If you have any questions or need further assistance, please open an issue on the GitHub repository or contact the maintainers.