Skip to main content

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

openjsoncanvas-1.0.5.tar.gz (3.8 kB view hashes)

Uploaded Source

Built Distribution

openjsoncanvas-1.0.5-py2.py3-none-any.whl (4.2 kB view hashes)

Uploaded Python 2 Python 3

Supported by

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