Hey there, fellow developer! Ready to dive into the world of Frame.io API integration? You're in for a treat. We'll be using the frameioclient
package to make our lives easier. Buckle up, and let's get started!
Before we jump in, make sure you've got:
First things first, let's get that frameioclient
package installed:
pip install frameioclient
Easy peasy, right?
Now, let's get you authenticated:
from frameioclient import FrameioClient client = FrameioClient("your_api_token")
Pro tip: Keep that API token safe! Consider using environment variables or a secure config file.
Let's start with some basic operations to get our feet wet:
# Get user info me = client.get_me() print(f"Hello, {me['name']}!") # List projects projects = client.get_projects() for project in projects: print(project['name']) # Access assets assets = client.get_assets(project_id)
Creating, updating, and deleting projects is a breeze:
# Create a project new_project = client.create_project({"name": "My Awesome Project"}) # Update a project client.update_project(new_project['id'], {"name": "My Even More Awesome Project"}) # Delete a project client.delete_project(new_project['id'])
Let's handle some assets:
# Upload an asset with open("cool_video.mp4", "rb") as file: asset = client.upload(project_id, file) # Download an asset client.download(asset['id'], "downloaded_video.mp4") # Update asset metadata client.update_asset(asset['id'], {"name": "Super Cool Video"})
Collaboration is key, so let's dive into that:
# Add a comment client.create_comment(asset['id'], {"text": "This looks great!"}) # Manage team members client.add_team_member(project_id, "[email protected]") # Share an asset share_link = client.create_share_link(asset['id'])
Stay in the loop with webhooks:
# Set up a webhook webhook = client.create_webhook(project_id, "https://your-server.com/webhook") # In your server code: def handle_webhook(request): event = request.json() if event['type'] == 'asset.created': print("New asset created!")
Always be prepared:
try: client.get_asset(non_existent_id) except FrameioClientException as e: print(f"Oops! {e}") # Respect rate limits from time import sleep sleep(1) # Add delays between requests if needed
Want to level up? Try these:
# Batch operations with client.batch() as batch: for asset_id in asset_ids: batch.update_asset(asset_id, {"status": "approved"}) # Integrate with other services # Example: Notify Slack when a new comment is added def notify_slack(comment): # Your Slack integration code here pass
And there you have it! You're now equipped to build some seriously cool Frame.io integrations. Remember, the API is your playground – don't be afraid to experiment and push the boundaries.
For more in-depth info, check out the Frame.io API docs and the frameioclient GitHub repo.
Now go forth and create something awesome! 🚀