Connecting to Data Tables
Once you have set up the Anvil Uplink, your local Python code can do anything a Server Module can do. This includes connecting to Data Tables in your Anvil App from your own machine.
Accessing your Data Tables
First, make sure you have enabled the Uplink.
Say, for example, we have a Data Table called ‘people’ that looks like this:
We’ll define a get_people
server function to access data in this table, and mark it as @anvil.server.callable
. Then, we’ll call this function from our local machine:
# In a script on your own machine (or anywhere)
# Connect the Uplink
import anvil.server
anvil.server.connect("[YOUR UPLINK KEY]")
# import app_tables to access your data tables
from anvil.tables import app_tables
@anvil.server.callable
def get_people():
people = app_tables.people.search()
for p in people:
print(f"This person's name is {p['name']}")
# Call the server function
anvil.server.call('get_people')
anvil.server.wait_forever()
This will produce the following output:
Querying your Data Tables
To use Anvil’s Query Operators, just add this line at the top of your code:
# In a script on your own machine (or anywhere)
import anvil.tables.query as q
Do you still have questions?
Our Community Forum is full of helpful information and Anvil experts.