Skip to main content

Client comparison

There are two official API clients for ftrack, a Python client and a JavaScript client. Besides the language they use they have some fundamental differences. The Python client has more helper functions and automatic conveniences. It's especially targeted towards backend scripting and pipeline automation. On the other hand, the JavaScript client adopts a thinner design, focusing on direct interactions with the ftrack API, which is better suited for web development and lightweight applications. For most use cases they are however interchangeable, and a team more used to working with one language or the other can confidently choose whichever fits them the best, as long as they are aware of the differences in how they work.

Making and committing changes

Python client

The Python client employs a Unit of Work pattern. This accumulates changes on an entity and then persists them all through a commit, failing all of them if one of them fails. This approach enables the creation and modification of entities in a more flexible manner. For instance, to create a user:

user = session.create('User', {})
user['username'] = 'jane'
session.commit()

This code snippet demonstrates how a user can be created and modified before committing the changes to the server.

To change the user, after the user variable is saved, we can simply assign a new value to the username property before committing again:

user['username'] = 'janet'
session.commit()

JavaScript client

The JavaScript client on the other hand, commits changes to the server immediately upon each operation. This design necessitates specifying all relevant details at the moment of creation:

const user = await session.create('User', {
username: 'jane'
})

To modify an entity, such as changing a username, the JavaScript client requires the use of the entity's primary key to perform an update:

// The ID is available in the returned data of the session.create
const userId = user.data.id
await session.update('User', [userId], {
username: 'janet'
})

⁤This approach ensures immediate feedback and synchronization with the server but requires more detailed management of entity states and IDs. ⁤

Caching

  • Python client: Offers caching functions, storing fetched data locally for quicker retrieval. This feature can enhance performance, especially in applications with repeated reads of the same data, but could cause issues with the data being stale if the developer is not careful.
  • JavaScript client: Does not include built in caching. Each request is sent directly to the server. Data will always be fresh, but it might increase the load on the server if no other caching is implemented in the application using the API client.

Attribute population

  • Python client: Capable of auto-populating missing attribute values upon access. This ensures that any properties needed will be lazy loaded if unavailable, but might create performance issues for certain fetch patterns.
  • JavaScript client: Requires explicitly specifying which attributes to fetch in each query. This provides more control over fetch timing and performance.

Event handling

Both API clients have an event handler capable of listening to and sending events through the ftrack event hub. The Python client supports more advanced event management features, including:

  • Session-local event handlers: Allows for events within session context.
  • Targeted events: Allows for targeting event to specific entities.
  • Stopping events: Provides mechanisms to halt the propagation of an events.
  • Advanced subscription expressions: Offers complex event filtering and handling based on custom logic and conditions.