Skip to main content

Easy query generation for the FTrack API.

Project description

ftrack-query

Easy query generation for the FTrack API. The official module is very powerful and well designed, but the custom SQL is not very pythonic to use, and dynamically generating queries can be difficult. This was created as an object orientated approach to building queries, using inspiration from the design of SQLAlchemy.

This class expands upon ftrack_api.Session.

Example Usage

with FTrackQuery() as session:
    Task = session.Task

    note = session.Note.create(
        content='My new note',
        author=session.User.where(username='peter').one(),
        category=session.NoteLabel.where(name='Internal').one(),
    )
    task = Task.where(Task.parent==session.Episode.first(), name='My Task').first()
    task['notes'].append(note)
    
    session.commit()

Equivalent examples from the API reference:

Note: If an entity type is used multiple times, it's recommended to use <Entity> = session.<Entity> after the session is initialised. To save space below, that part has been omitted.

# projects = session.query('Project')
# for project in projects:
#     print project['name']
projects = Project
for project in projects:
    print project['name']

# session.query('Project').all()
Project.all()

# session.query('Project where status is active')
Project.where(status='active')

# session.query('Project where status is active and name like "%thrones"')
Project.where(Project.name.like('%thrones'), status='active')

# session.query('Project where status is active and (name like "%thrones" or full_name like "%thrones")')
Project.where(or_(Project.name.like('%thrones'), Project.full_name.like('%thrones')), status='active')

# session.query('Task where project.id is "{0}"'.format(project['id']))
Task.where(project)

# session.query('Task where project.id is "{0}" and status.type.name is "Done"'.format(project['id']))
Task.where(Task.status.type.name=='Done', project=project)

# session.query('Task where timelogs.start >= "{0}"'.format(arrow.now().floor('day')))
Task.where(Task.timelogs.start>=arrow.now().floor('day'))

# session.query('Note where author has (first_name is "Jane" and last_name is "Doe")')
Note.where(Note.author.has(User.first_name=='Jane', User.last_name=='Doe'))

# session.query('User where not timelogs any ()')
User.where(~User.timelogs.any())

# projects = session.query('select full_name, status.name from Project')
Project.select('full_name', 'status.name')

# select name from Project where allocations.resource[Group].memberships any (user.username is "john_doe")
Project.select('name').where(Project.allocations.resource(Group).memberships.any(Project.user.username=='john_doe'))

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

ftrack-query-1.0.0.tar.gz (8.3 kB view details)

Uploaded Source

File details

Details for the file ftrack-query-1.0.0.tar.gz.

File metadata

  • Download URL: ftrack-query-1.0.0.tar.gz
  • Upload date:
  • Size: 8.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/2.0.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.36.1 CPython/3.8.0

File hashes

Hashes for ftrack-query-1.0.0.tar.gz
Algorithm Hash digest
SHA256 1a59753d78bd8eec39e367b04918e26a480759034c29d53edf3ea567b3fda90c
MD5 a0191fb9890667e05b5cee1109cd972b
BLAKE2b-256 b24abfe439ffc05a54d34b3a1438d7d934a97359f842c0b83f49955c77cda530

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page