Pyscript with forge

hi everyone, last time i asked if i can use python with forge framework and i’ve been told that’s not possible. so lately i heard of a framework called pyscript that help developers use python on the client side. so i’m asking if it’s possible to use it with forge.
Thanks in advance

Hi @jalelabbassi1920,

Apologies for the delayed reply. I had a play around with PyScript in Forge and yes, PyScript can be used in a Forge Custom UI application.

I’ve created a simple Hello World app and this is the index.html file of the working app:

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1" />
    <link rel="stylesheet" href="https://pyscript.net/latest/pyscript.css" />
    <script defer src="https://pyscript.net/latest/pyscript.js"></script>
    <title>React App</title>
  </head>
  <body>
    Hello world! <br>
    This is the current date and time, as computed by Python:
    <py-script>
from datetime import datetime
now = datetime.now()
now.strftime("%m/%d/%Y, %H:%M:%S")
    </py-script>
  </body>
</html>

The following are some things to note when building your PyScript app:

  1. Include the following permissions in the manifest:
permissions:
  content:
    scripts:
      - 'unsafe-eval'
  external:
    scripts:
      - 'https://pyscript.net'
      - 'https://cdn.jsdelivr.net'
    styles:
      - 'https://pyscript.net'
    fetch:
      client:
        - 'https://cdn.jsdelivr.net'
  1. Do not build the app and deploy the built version (for example: npm run build). Building the application will generates a minified html which removes the white spaces that the Python language needs. To go around this I had to modify the index.html file within the build folder.

Please note that we do not officially support PyScript, so if you do encounter any problems when making a PyScript Forge app, we might not be able to provide the assistance you require.

Have fun coding!

Cheers,
Camelia

1 Like

I’m actually a bit surprised that unsafe-eval is allowed in Forge Custom UI that is loading external scripts from CDN?

The Security requirements for cloud applications indeed does not mention it for Forge apps, but that seems like an omission?

2 Likes

Thanks so much.
SO can i submit it to marketplace? :thinking: :smiley: :thinking: