It’s been some time since we released our new API last summer. The API has already seen a broad adoption among our users and we’ve got some really great feedback from the ftrack community.

Part of this feedback, which we’ve heard from many of you, is the need for paging and ordering of query results.

You’ll be happy to hear we’ve now solved this! Let’s take a brief look at how it works…

Order by

Sorting the result set is essential if you want to benefit from the paging capabilities. With the new order by keyword this is easily achieved:


import ftrack_api

# Let us create the api session. 
session = ftrack_api.Session()

# Fetch all users, order by first name.
query = session.query('User order by first_name')
for user in query:
    print user['first_name']

# We can also change the direction of the order by using asc/desc.
query = session.query('User order by first_name desc')
for user in query:
    print user['first_name']

 

Paging

By combining the two new keywords limit and offset along with order by you can now page the result set from your server. Let’s have a look at how this works:


# Get query and limit the result.
query = session.query('User order by first_name limit 5')

for user in query:
    print user['first_name']

# Now we want to get the next 5 items of the result:
query = session.query(
    'User order by first_name offset 5 limit 5'
)
for user in query:
    print user['first_name']

 

And that’s it! You can now use this approach to page results from the ftrack server when using the new API.

If you have any questions please feel free to reach out to us at [email protected]

Until next time!

// ftrack dev team