What I’m trying to do:
I have to use the Uplink to connect some custom server code to my Anvil application because Anvil is unable to handle the dependency Ta-Lib import. In order to do that, I’ve created a Factory Class on my local machine that tries to invoke the portable class feature. The class looks like this:
import anvil.server
import talib as ta
@anvil.server.portable_class('_Indicator')
class IndicatorCalculator:
def calculate(self,indicator_name, *args):
indicator_method = get_indicator(indicator_name)
return indicator_method(*args)
The get_indicator
method maps to the correct function in my Server Uplink to calculate my indicator.
What I’ve tried and what’s not working:
I’ve tried following what @stucork wrote here (as well as the Anvil Documentation) : How do I use portable classes with uplink? (updated) - #9 by nashtdean but can’t seem to figure out how the Portable Classes connect to the Uplink. I’ve created a simple sample of what I thought I’m supposed to do (see below), but if I stop the Uplink server on my local machine, the App still runs the Portable Class defined in Portable_Classes
module in the Anvil app.
If I remove the imports for the Test_Class
that point to Portable_Classes
and replace it with the module on my local machine called uplink_module
, I get an import error. I am also unsure if I need to be using the Client Uplink for my portable class?
Code Sample:
File Structure on Local Uplink:
PROJECT DIRECTORY
—>uplink_module.py
—>client_uplink.py
—>server_uplink.py
uplink_module.py on my local machine
import anvil.server
@anvil.server.portable_class('_Test')
class Test_Class():
def __init__(self):
self.say_hello()
def say_hello(self):
print("Hello, world from Uplink")
client_uplink.py on local machine
import anvil.server
anvil.server.connect("UPLINK_KEY_REDACTED")
anvil.server.wait_forever()
You can see how I’ve structured the Portable Class example in sample app below, testing the call in the Form1 console printing “Hello, world from Uplink”
Clone link: