Flow Production Tracking Python API

repository·master·Indexed 43 days ago

https://github.com/shotgunsoftware/python-api

The official Autodesk-maintained library for programmatic access and tool integration with Flow Production Tracking. It provides the shotgun_api3 module for interacting with platform data and services, including support for user and script-based authentication, attachment management, and timezone conversions via sgtimezone. The API also includes Mockgun for unit testing and provides guidance for IronPython compatibility and standalone application packaging.

Tokens
25K
Snippets
66
Records
109
Agent score
54%

What's inside Flow Production Tracking Python API

  1. Overview of the Flow Production Tracking Python API

    master

    The Flow Production Tracking (FPTR) Python API (also known as api3) is a low-level, CRUD-based interface designed for integrating tools with Flow Production Tracking.

    Key characteristics:

    • Low-level design: The API avoids built-in automation or 'smarts' to allow studios to implement their own custom logic and wrappers.
    • CRUD operations: It provides a straightforward way to Create, Read, Update, and Delete entities within the platform.
    • Media Management: Beyond basic metadata, the API includes methods for managing various media types, including thumbnails, filmstrip thumbnails, images, and both locally and remotely linked media (e.g., Quicktimes).
  2. Overview of Flow Production Tracking Python API

    master
    The Flow Production Tracking Python API is the official Autodesk-maintained library for accessing Flow Production Tracking and integrating it with other tools. It allows developers to programmatically interact with the platform's data and services.
  3. Understand permissions for users and scripts

    master

    Both users and scripts are governed by permission roles assigned within Flow Production Tracking.

    Script Permissions

    • The default permission role for new scripts is API Admin User, which grants full access (create, update, delete, edit audit fields, and create event log entries).
    • You can change the default role assigned to new scripts in your site preferences.

    User Permissions

    • Scripts using user-based authentication are strictly bound by the permissions of the user account provided. If the user lacks permission to edit a specific field (e.g., the status field on a Shot), the API will raise an exception when attempting that action.
  4. How splits influence Task dates and vice versa

    master

    When working with tasks that have splits, the relationship between start_date, due_date, duration, and the splits list is automated:

    Date/Duration Priority

    • If splits are provided, the supplied start_date, due_date, and duration fields are ignored for the initial update. Instead, start_date is inferred from the earliest split and due_date from the last split.

    Automatic Adjustments

    • Changing start_date: The first split moves to the new start_date, and all subsequent splits shift to maintain existing gap lengths and respect workday rules.
    • Changing due_date: The last split moves to end on the new due_date, and all prior splits shift to maintain gap lengths and respect workday rules.
    • Changing duration:
      • Longer duration: Additional days are added to the end of the last split.
      • Shorter duration: Starting from the latest splits, segments are either removed or shortened until the new duration is met.
    • Setting due_date in a gap: If the due_date is set within a gap between splits, the later splits are removed, and the day of the new due_date becomes a work day.
  5. Structure of Local File Values

    master

    When querying a field that contains a local file link, the returned dictionary contains several keys. Note that all keys are returned even if they are None (e.g., if a specific platform path is not set).

    Available Keys:

    • content_type (str): The MIME-type of the file (automatically guessed from extension unless overridden).
    • link_type (str): Always 'local' for these fields.
    • name (str): The display name of the file.
    • local_path (str): The full path to the file on the current platform. The API automatically maps platform-specific keys to this field for convenience.
    • local_path_linux (str): Read-only. Full path on Linux.
    • local_path_mac (str): Read-only. Full path on macOS.
    • local_path_windows (str): Read-only. Full path on Windows.
    • local_storage (dict): Read-only. The LocalStorage entity applied to this link.
    • relative_path (str): Read-only. The path relative to the local_storage root.
    • url (str): Read-only. A file:// URI pointing to the local_path.
  6. Querying ConnectionEntities for many-to-many relationships

    master

    Connection entities are used to track information on the specific instance of a relationship between two entities (many-to-many). An example is the PlaylistVersionConnection, which stores the sg_sort_order for a specific Version within a specific Playlist.

    You can access fields from the linked entities using dot notation in the fields list with the syntax: fieldname.EntityType.fieldname.

    Example: To get the code of a Version linked to a PlaylistVersionConnection, use version.Version.code.

    filters = [['playlist', 'is', {'type':'Playlist', 'id':4}]]
    fields = ['playlist.Playlist.code', 'sg_sort_order', 'version.Version.code', 'version.Version.user', 'version.Version.entity']
    order=[{'column':'sg_sort_order','direction':'asc'}]
    result = sg.find('PlaylistVersionConnection', filters, fields, order)
  7. Optimize queries using field hopping with dot notation

    master

    To reduce API round-trips and improve application speed, you can use "field hopping" (dot notation) to query or return data from linked entities in a single call. Instead of performing multiple queries to resolve relationships, you can traverse a single-entity relationship using the syntax field.EntityType.field_name.

    Key Rules:

    • Use dot notation to join field names to entity types in a chain.
    • Limitation: Due to performance concerns, dot notation chains are only supported for single-entity relationships. You cannot pull data through a multi-entity field (e.g., a list of entities).
    • This technique works with both sg.find() and sg.create() methods.
    # Example 1: Querying via a linked entity's field
    # Instead of finding the Project first, query Shots directly by Project name
    project_name = 'Big Buck Bunny'
    sg_shots = sg.find("Shot", [['project.Project.name', 'is', project_name]], ['code'])
    
    # Example 2: Returning linked data in the results
    # Retrieve the shot code AND the status of the associated Sequence
    project_name = 'Big Buck Bunny'
    sg_shots = sg.find(
        "Shot", 
        [['project.Project.name', 'is', project_name]],
        ['code', 'sg_sequence.Sequence.sg_status_list']
    )
  8. Manage event logging for scripts

    master

    By default, actions performed by scripts using script-based authentication are recorded in the Flow Production Tracking event log.

    Disabling Event Logging

    If a script performs high-volume, non-critical data pushes (such as reference data from an external asset management system) that would clutter the event log, you can disable logging:

    • Un-check the Generate Events checkbox on the script's detail page or the main Scripts admin page.

    Warning: Disabling event logging prevents the email notifier from triggering, as the notifier relies on the event log to identify actions that require notification.

  9. How Task date scheduling works in Flow Production Tracking

    master

    When using update() to modify Task dates, Flow Production Tracking performs automatic calculations for start_date, due_date, and duration. The system follows specific precedence rules to ensure schedule consistency:

    • Updating start_date: Automatically updates due_date (keeping duration constant).
    • Updating due_date: Automatically updates duration (keeping start_date constant).
    • Updating duration: Automatically updates due_date (keeping start_date constant).
    • Precedence of Fields: If both start_date and due_date are provided in a single update, duration is ignored. The system sets start_date first, then due_date, and calculates the new duration based on the difference.
    • Milestones:
      • Set milestone to False before updating other schedule fields if you want to avoid losing start_date, due_date, or duration values.
      • If milestone is set to True, duration is ignored.
      • Setting milestone to True while providing conflicting start_date and due_date values will raise an Exception.
    • Order of Operations: If due_date and duration are provided without a start_date, duration is set first, then due_date is updated to prevent the duration change from overwriting the due date.

    Note: The duration field is stored in minutes.

  10. Understand the Attachment entity structure

    master

    In Flow Production Tracking, files are stored as Attachment entities. An Attachment can represent an uploaded file, a web link, or a local file reference.

    Important Note: This documentation describes the structure of the Attachment entity. If you simply want to upload a file, use the Shotgun.upload or Shotgun.upload_thumbnail methods instead.

    Default Fields

    • description (str): Optional descriptive text.
    • this_file (dict): The core file reference. This field cannot be modified after creation. It contains a link_type key which determines the file type.
    • filename (str): Automatically assigned for uploads.
    • file_size (int): Automatically assigned for uploads (in bytes).
    • id (int): Internal ID.
    • attachment_links (list): Entity dictionaries used for linking the attachment to multiple entities.
    • attachment_reference_links (list): Similar to attachment_links, but used specifically for reference links.
    • project (dict): Required. The Project entity this attachment belongs to.
    • sg_status_list (str): Status short code.
    • tag_list (list): List of string tags.
    • image (str): URL to the thumbnail image.
    • sg_type (str): Optional designation for attachment types.
    • processing_status (str): Reflects processing state (e.g., 'Thumbnail Pending').