Skip to main content

Bring the power of ProcessingJS (aka P5) to Streamlit. This module allows you to create Processing sketches, interact with those sketches using the mouse and keyboard, and share data between your Processing Sketch and Stremalit.

Project description

streamlit_p5

Embed your processing sketches in Streamlit! Check out the demo here

You can find the source code at: https://github.com/salable/streamlit-p5

Installation instructions

pip install streamlit streamlit_p5

Quickstart

streamlit run example.py

Usage instructions

The sketch object takes a few arguments:

  • sketch : a string representing your P5js sketch
  • width : width of the element in Streamlit
  • height : height of the element in Streamlit (make sure to match these with your sketch!)
  • data : a Python dict to pass to the p5 sketch

Example:

Basic

import streamlit as st
from streamlit_p5 import sketch

p5_sketch = sketch("""
function setup() {
   createCanvas(700, 500);
}

// The background function is a statement that tells the computer
// which color (or gray value) to make the background of the display window 
function draw() {
   background(204, 153, 0);
}
""", width=700, height=500)

Advanced

import streamlit as st
from streamlit_p5 import sketch

value = sketch("""
let word=""
function setup() { 
  createCanvas(700, 500);
  noStroke();
  word=dataToPass.name. // get value passed from Streamlit
}

function draw() {
  background(204, 120);
  fill(0)
  textFont('Courier New')
  textSize(50)
  text(word, mouseX, mouseY)
}

function mousePressed() {
  sendDataToPython({  //Send data to Streamlit - causes a re-render
          value: {
            mouseX: mouseX,
            mouseY: mouseY
          },
          dataType: "json",
        })
}
""", data={
  "name" : "Bob the Builder"
}, width=700, height=500)

Wanna build this from source? just run:

python setup.py sdist bdist_wheel && twine upload dist/*

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

streamlit_p5-0.0.4.tar.gz (248.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

streamlit_p5-0.0.4-py3-none-any.whl (497.4 kB view details)

Uploaded Python 3

File details

Details for the file streamlit_p5-0.0.4.tar.gz.

File metadata

  • Download URL: streamlit_p5-0.0.4.tar.gz
  • Upload date:
  • Size: 248.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.0.0 CPython/3.12.3

File hashes

Hashes for streamlit_p5-0.0.4.tar.gz
Algorithm Hash digest
SHA256 cb2c1bbba731ca0354f280c4f69d92c406987e65a55ebe5ab9c44c4ae8a2f456
MD5 39536d2a50a51c7b6e94464899c17ffb
BLAKE2b-256 388c32f6ac529752c76d3afa282caf07a3e8bbbeffbb4d196041de9ebdc2118f

See more details on using hashes here.

File details

Details for the file streamlit_p5-0.0.4-py3-none-any.whl.

File metadata

  • Download URL: streamlit_p5-0.0.4-py3-none-any.whl
  • Upload date:
  • Size: 497.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.0.0 CPython/3.12.3

File hashes

Hashes for streamlit_p5-0.0.4-py3-none-any.whl
Algorithm Hash digest
SHA256 96cf88999d7c899b7d9ab1ef98ac38815e08339bd926a1d9cc3246e140647d00
MD5 be6f9d3a1041ad5bebc18e20b941e5bf
BLAKE2b-256 884c3aa38791ee2d58c66aed2fd86b92da7c49642c41934f208cfcd7313b4d00

See more details on using hashes here.

Supported by

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