Skip to main content

Blackprint

Blackprint Engine for Python

Run exported Blackprint on Python environment.

Documentation

Warning: This project haven't reach it stable version (semantic versioning at v1.0.0)
But please try to use it and help improve this project

This engine is designed to be similar with engine-js, some API and property will be similar.

Minimum Python version >= 3.10

$ pip install blackprint-engine

Defining Blackprint Node and Interface

Because Python does support class-based programming and to make the node import more effective and easier, this engine will only support Node/Interface that declared with classes.

But before that, we need to create a folder to store our Node/Interface logic. For the example /BPNode. And then import it like below:

import Blackprint
import BPNode # Import your own nodes located on ./BPNode directory

Defining custom node

# file: ./BPNode/Example/Hello.py

@Blackprint.registerNode('Example/Hello')
class Hello(Blackprint.Node):
    # Please remember to capitalize the port name
    # Set the output port structure for your node (Optional)
    output = {
        'Changed': Blackprint.Types.Trigger,
        # this.output['Changed']() -- To call every connected port

        'Output': int,
        # this.output['Output'] = 246 -- To assign value to output port
    }

    # Set the input port structure for your node (Optional)
    input = {
        'Multiply': int,
        # val = this.input['Multiply'] -- To obtain value from input port
    }

    def __init__(instance):
        # Call the parent constructor first, passing the instance (Blackprint.Engine)
        super(Hello, this).__init__(instance)

        # Set the Interface, let it empty if you want
        # to use default empty interface "setInterface()"
        iface = this.setInterface('BPIC/Example/Hello')
        iface.title = "Hello" # Set the title for debugging

Let's also define our custom interface, this is optional and needed only if you want to provide access for other developer. Just like an API (Application Programming Interface).

# same file: ./BPNode/Example/Hello.py

# Your Interface namespace must use "BPIC" as the prefix
@Blackprint.registerInterface('BPIC/Example/Hello')
class HelloIFace(Blackprint.Interfaces):
    def __construct(node):
        # Call the parent constructor first, passing the node (Blackprint\Node)
        super(HelloIFace, this).__init__(node)
        # this.node => Blackprint.Node

        # Define IFace's data (optional if you want to export/import data from JSON)
        # Because getter/setter feature only available on class, we will create from `class MyData`
        this.data = MyData(this)
        # this.data.value == 123 (if the default value is not replaced when importing JSON)

    def recalculate():
        # Get value from input port
        multiplyBy = this.node.input['Multiply']

        # Assign new value to output port
        this.node.output['Output'] = this.data.value * multiplyBy

# Getter and setter should be changed with basic property accessor
class MyData:
    # Constructor promotion, iface as private MyData property
    def __init__(this, iface):
        this._iface = iface

    _value = 123

    @property
    def value();
        return this._value

    @value.setter
    def value(val);
        this._value = val
        this._iface.recalculate() # Call recalculate() on HelloIFace

Creating new Engine instance

# Create Blackprint Engine instance
instance = Blackprint.Engine()

# You can import nodes with JSON
# if the nodes haven't been registered, this will throw an error
instance.importJSON('{...}')

# You can also create the node dynamically
iface = instance.createNode('Example/Hello')

# ----

# Change the default data 'value' property
iface.data.value = 123

# Assign the 'Multiply' input port = 2
iface.node.input['Multiply'] = 2

# Get the value from 'Output' output port
print(iface.node.output['Output']) # 246

Example

csZIeKxr7j

This repository provide an example with the JSON too, and you can try it with Python 3:

# Change your working directory into empty folder first
$ git clone --depth 1 https://github.com/Blackprint/engine-python .
$ pip install -e .
$ python ./example/simple.py

Metadata

Release files for blackprint-engine 0.9.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Built distribution (wheel)

Table of built distributions (wheels) for blackprint-engine 0.9.0
File Interpreter ABI Platform
blackprint_engine-0.9.0-py3-none-any.whl Python 3 none any Details

Release files / blackprint_engine-0.9.0-py3-none-any.whl

Download URL blackprint_engine-0.9.0-py3-none-any.whl
Size 42.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
372405f69d6369249db3d1072a5f2771adca02821fb32677ca1630282d6690df
BLAKE2b-256 checksum
How to use checksums
329bc8760c3bbc461c879b6bcf097f8dae11ea75ee5957f626994803ae268cad
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.1 CPython/3.11.4

Security for blackprint-engine 0.9.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page