External Python scripts in Anvil in real time

Hello everyone,

I done some scripts in python and their general aspect is like this

Like you can see I have a menu, and when a user choose is option I comunicate with i2c devices and others protocols.

I want to know if this is possible to run in an Anvil web App.
Like you may realize this need to be in real time and fast.

I will leave some videos that i do, to you have some ideas:

What I want is, when I click in a button the script will run in the browser in real time and of course it needs to acept inputs (most of the times, the inputs are numbers).

This is possible in Anvil ?
I try to use Uplink but it gives errors.

Thanks

If there are more than a handful users accessing the same realtime data, Anvil seems not to be a good choice since every sever request takes around 2 or 3 seconds or more depends on the number of users and the size of the data.

If the data is less likely to change often and not sensitive, loading all data to client side can make the app extremely fast.

Oh yes, i forgot to say, these scripts are in a RaspberryPi (SO - Raspbian).
Only one user will use it, the raspberrypi itself.
The data is not sensitive.

Thanks for the answer, but how can I run these scripts that I have in my raspberry ?
I search in anvil site and can’t find it.

Hi @marcosandretavaresfe, the open source server app can be installed directly in your raspberry

I already do that thanks … but I will try to import the python script in anvil and then associate to my “button_click” funtion

Ok this is what I do:
I paste my script into this location

then open the app and give this error:
image

This is my button:


I try ftdi.py, only ftdi() and nothing … then I try display the script in a “text area” and nothing

I made a simple search in google and I think this error is related with skulpt

what is the contents of the ftdi.py file

I think you might need to use the syntax

from .ftdi import myfunction

def button_click(self, **event_args):
    self.display_area.text = myfunction()

Or perhaps the file contains unsupported syntax.
Skulpt is not a full python implementation but a subset.

1 Like

Well the content of that file is a bit long … the purpose of it is to test a PCB, its my final university projet … it sees how many COM Ports has the PC, coming from the FTDI Chip, and see if each COM Port is comunicating

Just like you can see, my main function calls anothers functions according the user choice in the main menu

And I hove more of the script/programs, each one test one different PCB … and Im trying to do a web app for this

If Anvil could implement my scripts directly in the browser, without I have to change the scripts, that would be Awnsome !!

Else I would like to know if there is another options … or whats the best way to do that

Thanks for your replies

Uplink may be your solution. Please have a look
https://anvil.works/docs/uplink

1 Like

I try uplink but nothing … or i made something wrong…

i put the “@anvil.server.callable” before main function … then in the beginig of the code … differente results and gives error in app

i can try again

Yeah that module won’t run on the client side. Client side stuff only knows about your browser and not your machinery so things like os don’t make sense and aren’t supported by the skulpt architecture.

The two approaches will be to use uplink or to use the anvil standalone runtime. As suggested above.

I try in some days ago … I just cant

You try … or someone …and tell me how to did, if you did it right

I have in this link all of my other scripts

Hi @marcosandretavaresfe,

Here is a video walkthrough of using the Uplink to control a script on a Raspberry Pi. You might find this helpful:

2 Likes

Thank you for your reply @meredydd … it works this time

I have now 2 another questions:

  • Uplink can work without internet ?

  • How Can I saw that message in my web app ?

Ok, some feedback:

with this tutorial (https://anvil.works/learn/workshops/test-manager) I made this

the 2Âş question is answered :slight_smile: (now I have to try with my own scripts)

Great. The first question - you need internet for anvil uplink.

One of the reasons for open sourcing the anvil runtime is to use anvil where internet isn’t feasible/reliable.

The Anvil Runtime Engine is Now Open Source

So if your project demands no internet you might have to go down this route.

1 Like

without internet:

what I miss ?

I run the server without internet and it keeps sendind this messages as normal i think:
image

You still need Internet for uplink.

It looks like you’re combining the app-server with anvil uplink?

But on the app-server you can pip install what you need because you are running the server. Then put your server functions in the server modules rather than using uplink. This way you don’t need to connect using anvil uplink at all.

I just run the new open source server … and try to do, without internet, what I do before and nothing

Ok, I will try to put my function on the server … thanks