Python SDK
The official Pipe2.ai Python SDK provides fully typed async GraphQL operations with Pydantic models. Generated with ariadne-codegen.
Installation
pip install pipe2Quick start
import asynciofrom pipe2 import Pipe2Client
async def main(): client = Pipe2Client("YOUR_JWT_TOKEN")
# List all pipelines result = await client.get_pipelines() for p in result.pipelines: print(f"{p.name} — {p.credit_cost} credits")
# Run a pipeline run = await client.run_pipeline( pipeline_slug="selfie-universe", input={"photo_url": "https://..."}, ) print(f"Run ID: {run.run_pipeline.run_id}")
asyncio.run(main())Authentication
Pass your JWT token when creating the client:
client = Pipe2Client("eyJhbGciOiJFZERTQSIs...")Sign up
from pipe2 import Pipe2Client
# Use an unauthenticated client for auth flowsauth = Pipe2Client("")
# 1. Start a signup flowflow = await auth.init_signup_flow()
# 2. Submit signup credentialssignup = await auth.submit_signup_flow( flow_id=flow.init_signup_flow.id, email="user@example.com", password="securepassword", name="Jane Doe", csrf_token=flow.init_signup_flow.csrf_token,)
# 3. Verify email (check inbox for the 6-digit code)vflow = await auth.init_verification_flow(email="user@example.com")await auth.submit_verification_code( flow_id=vflow.init_verification_flow.id, code="123456", csrf_token=vflow.init_verification_flow.csrf_token,)
# 4. Create an authenticated client with the tokenclient = Pipe2Client(signup.submit_signup_flow.token)Sign in
from pipe2 import Pipe2Client
auth = Pipe2Client("")
# 1. Start a login flowflow = await auth.init_login_flow()
# 2. Submit credentialslogin = await auth.submit_login_flow( flow_id=flow.init_login_flow.id, email="user@example.com", password="securepassword", csrf_token=flow.init_login_flow.csrf_token,)
# 3. Use the tokenclient = Pipe2Client(login.submit_login_flow.token)pipelines = await client.get_pipelines()Social login
social = await auth.submit_social_login(provider="google") # or "github", "microsoft"# Redirect user to social.submit_social_login.redirect_urlAvailable operations
Pipelines
# List all pipelinesresult = await client.get_pipelines()
# Run a pipelinerun = await client.run_pipeline( pipeline_slug="baby-generator", input={"photo_url_1": "https://...", "photo_url_2": "https://..."},)
# Get a specific runrun_detail = await client.get_pipeline_run(id="run-uuid")
# List run history with paginationruns = await client.get_pipeline_runs(limit=10, offset=0)Assets
# Get a presigned upload URLupload = await client.request_upload(filename="photo.jpg", content_type="image/jpeg")# PUT the file to upload.request_upload.upload_url
# Create an asset recordasset = await client.create_asset( asset_type="image", url=upload.request_upload.asset_url, tags=["input", "selfie-universe"],)
# List your assetsassets = await client.get_user_assets(limit=20)
# Delete an asset (also removes from storage)await client.delete_asset_action(id="asset-uuid")
# Update tagsawait client.update_asset_tags(id="asset-uuid", tags=["favorite"])Credits
# Check your balancebalance = await client.get_credit_balance()print(f"Available: {balance.get_credit_balance.available}")
# View transaction historyhistory = await client.get_credit_history()Personal access tokens
# Create a new tokentoken = await client.create_personal_access_token(name="My Integration")print(token.create_personal_access_token.token) # Save this — shown only once
# List tokenstokens = await client.get_my_api_keys()
# Revoke a tokenawait client.revoke_personal_access_token(id="token-uuid")Plans & billing
plans = await client.get_plans()credit_packs = await client.get_credit_packs()subscription = await client.get_subscription()Subscriptions
Watch a pipeline run status in real time. The SDK returns a typed async iterator:
# Start a pipelinerun = await client.run_pipeline( pipeline_slug="selfie-universe", input={"photo_url": "https://..."},)
# Subscribe — async iterator with typed updatesasync for result in client.watch_pipeline_run(run_id=run.run_pipeline.run_id): r = result.pipeline_runs_by_pk print(f"Status: {r.status}")
if r.status in ("completed", "failed"): if r.assets: print(f"Result: {r.assets[0].url}") break