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()


Out[26]:
'd4a1304c20b20390f1dca3dac190a8bb0fe5b5aca5d7c40562d4'

Get a foundset from the database/layout


In [27]:
foundset = fms.get_records(limit=2)
foundset


Out[27]:
<Foundset consumed_records=0 is_complete=False>

Now we have a foundset instance we can iterate over:


In [28]:
for record in foundset:
    print(record)


<Record id=2 modification_id=7 is_dirty=False>
<Record id=3 modification_id=8 is_dirty=False>

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()


Out[30]:
['id',
 'name',
 'drink',
 'portrait',
 'creation',
 'modification',
 'recordId',
 'modId',
 'portal_notes']

Now, if we want to get the name, we just access it via the attribute:


In [31]:
record.name


Out[31]:
'David'

...or via the key:


In [32]:
record['drink']


Out[32]:
'Coffee'

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


Out[33]:
<Foundset consumed_records=0 is_complete=False>

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


Out[34]:
<Record id=2 modification_id=None is_dirty=False>

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']


Out[35]:
'A note for David.'

Logout

Let's logout and destroy our opened session.


In [36]:
fms.logout()


Out[36]:
True