Skip to main content

A simple library for working with JSON Canvas (previously known as Obsidian Canvas) files.

Project description

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,
)

# Create a new canvas
canvas = Canvas(nodes=[], edges=[])

# Add some nodes
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)

# Add an edge
edge = Edge(
    fromNode=text_node.id,
    fromSide="bottom",
    toNode=file_node.id,
    toSide="top",
    color=Color("#FF0000"),
    label="Edge 1",
)
canvas.add_edge(edge)

# Save the canvas as JSON
json_str = canvas.to_json()

# Load the canvas from JSON
loaded_canvas = Canvas.from_json(json_str)

# Get a node
node = loaded_canvas.get_node(text_node.id)

# Get connections for a node
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.

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

PyJSONCanvas-1.0.2.tar.gz (6.6 kB view details)

Uploaded Source

File details

Details for the file PyJSONCanvas-1.0.2.tar.gz.

File metadata

  • Download URL: PyJSONCanvas-1.0.2.tar.gz
  • Upload date:
  • Size: 6.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.9.6 readme-renderer/40.0 requests/2.31.0 requests-toolbelt/1.0.0 urllib3/1.26.16 tqdm/4.66.1 importlib-metadata/6.8.0 keyring/24.2.0 rfc3986/1.5.0 colorama/0.4.6 CPython/3.10.14

File hashes

Hashes for PyJSONCanvas-1.0.2.tar.gz
Algorithm Hash digest
SHA256 3bf3d12b8d3c758a21e103a4c2939f1d79b4b21b3159abf9fb936242ca902b12
MD5 d2a3ce35f3226e2f105d2130c8f25048
BLAKE2b-256 489f75b7ceff30965eb3b37c4a5add339b755af2abf172362506d818fa90e6c7

See more details on using hashes here.

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