#!/usr/bin/env python # coding: utf-8 # In[23]: # hide ssl warnings for this test. import requests requests.packages.urllib3.disable_warnings() # # Reading data with python-fmrest # This is a short example on how to login, get a foundset from a database layout, read field values, and eventually logout. # ## Import the module # In[24]: import fmrest # ## Create the server instance # In[25]: fms = fmrest.Server('https://10.211.55.15', user='admin', password='admin', database='Contacts', layout='Demo', verify_ssl=False ) # ## Login # The login method obtains the access token. # In[26]: fms.login() # ## Get a foundset from the database/layout # In[27]: foundset = fms.get_records(limit=2) foundset # Now we have a foundset instance we can iterate over: # In[28]: for record in foundset: print(record) # We have two records in our foundset. Let's see what is in them: # ## Inspect a record instance # Let's look at the available keys (fields) of the first record in the foundset: # In[29]: record = foundset[0] # In[30]: record.keys() # Now, if we want to get the name, we just access it via the attribute: # In[31]: record.name # ...or via the key: # In[32]: record['drink'] # ## What about portals? # By looking at the keys, we can see that we also have portals on our layout (keys starting with "portal_"). Let's look at `portal_notes`. # # It is, again, a foundset instance. # In[33]: portal = foundset[0].portal_notes portal # We could go through the rows like this # ``` # for row in portal: # print(row) # ``` # Or access a particular row directly: # In[34]: row = portal[0] row # We get back a record instance just like the ones before. Note, though, that we access fields in portal rows with the table occurrence prefix (just like in FileMaker Pro): # In[35]: row['Notes::note'] # ## Logout # Let's logout and destroy our opened session. # In[36]: fms.logout()