Unofficial Python client for Canva Connect API
Project description
Canva Connect API Python Client
Note: This is an unofficial Python client for the Canva Connect API. It is not officially endorsed or maintained by Canva.
A comprehensive Python client library for the Canva Connect API, enabling developers to integrate Canva's powerful design capabilities into their applications.
🚀 Features
- Complete API Coverage: All Canva Connect API endpoints
- Type Safety: Full type annotations with Pydantic v2
- Modern Python: Supports Python 3.9+
- OAuth 2.0 + PKCE: Secure authentication flow
- Auto-generated: Based on official OpenAPI specification
- Production Ready: Comprehensive error handling and retries
📦 Installation
pip install canva-connect-api
🔧 Quick Start
import openapi_client
from openapi_client.api.design_api import DesignApi
from openapi_client.api.autofill_api import AutofillApi
# Configure API client
configuration = openapi_client.Configuration(
host="https://api.canva.com/rest",
access_token="your_access_token_here"
)
# Create API instances
with openapi_client.ApiClient(configuration) as api_client:
design_api = DesignApi(api_client)
autofill_api = AutofillApi(api_client)
# List user's designs
designs = design_api.list_designs()
print(f"Found {len(designs.items)} designs")
🔑 Authentication
Before using the API, you need to set up OAuth 2.0 authentication:
- Create a Canva App in the Canva Developer Portal
- Configure OAuth settings and scopes
- Implement OAuth flow in your application
from openapi_client.api.oauth_api import OauthApi
# Step 1: Direct user to authorization URL
auth_url = "https://www.canva.com/api/oauth/authorize"
params = {
"code_challenge": "your_code_challenge",
"code_challenge_method": "S256",
"scope": "design:read design:write asset:read",
"response_type": "code",
"client_id": "your_client_id"
}
# Step 2: Exchange code for tokens
oauth_api = OauthApi(api_client)
token_response = oauth_api.exchange_access_token(
# ... token exchange parameters
)
🎆 Examples
Autofill Templates
from openapi_client.api.autofill_api import AutofillApi
from openapi_client.models.create_design_autofill_job_request import CreateDesignAutofillJobRequest
# Autofill a brand template with data
autofill_request = CreateDesignAutofillJobRequest(
brand_template_id="your_template_id",
data=DataTable(
rows=[DataTableRow(
cells=[
StringDataTableCell(value="Hello World"),
StringDataTableCell(value="Welcome Message"),
DatasetImageValue(url="https://example.com/image.jpg")
]
)]
)
)
autofill_job = autofill_api.create_design_autofill_job(autofill_request)
print(f"Job created: {autofill_job.job.id}")
Upload and Manage Assets
from openapi_client.api.asset_api import AssetApi
# Upload an asset
asset_api = AssetApi(api_client)
upload_job = asset_api.create_asset_upload_job(
# ... upload parameters
)
# List user's assets
assets = asset_api.list_assets()
for asset in assets.items:
print(f"Asset: {asset.name} - {asset.id}")
Export Designs
from openapi_client.api.export_api import ExportApi
from openapi_client.models.create_design_export_job_request import CreateDesignExportJobRequest
# Export design as PNG
export_api = ExportApi(api_client)
export_request = CreateDesignExportJobRequest(
design_id="your_design_id",
format=ExportFormat(
type="png",
quality="high"
)
)
export_job = export_api.create_design_export_job(export_request)
print(f"Export job: {export_job.job.id}")
📋 Available APIs
All URIs are relative to https://api.canva.com/rest
| API | Description |
|---|---|
| AppApi | Manage Canva apps |
| AssetApi | Upload and manage user assets |
| AutofillApi | Automated template data population |
| BrandTemplateApi | Access brand templates |
| CommentApi | Comments and collaboration |
| ConnectApi | API connectivity features |
| DesignApi | Create and manage designs |
| DesignImportApi | Import designs from files |
| ExportApi | Export designs to various formats |
| FolderApi | Organize designs and assets |
| OauthApi | OAuth authentication |
| ResizeApi | Resize existing designs |
| UserApi | User profile and capabilities |
🏗️ Requirements
- Python 3.9+
- urllib3 (>=2.1.0,<3.0.0)
- python-dateutil (>=2.8.2)
- pydantic (>=2)
- typing-extensions (>=4.7.1)
- lazy-imports (>=1,<2)
📚 Documentation
🤝 Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
- Fork the repository
- Create your feature branch (
git checkout -b feature/AmazingFeature) - Commit your changes (
git commit -m 'Add some AmazingFeature') - Push to the branch (
git push origin feature/AmazingFeature) - Open a Pull Request
📄 License
This project is licensed under the MIT License - see the LICENSE file for details.
⚠️ Disclaimer
This package is an unofficial Python client for the Canva Connect API. It is not officially endorsed or maintained by Canva. Canva® is a trademark of Canva Pty Ltd.
The official Canva Connect API documentation can be found at: https://www.canva.dev/docs/connect/
🆘 Support
📈 Changelog
See CHANGELOG.md for a list of changes and version history.
Generated from OpenAPI specification v2024-06-18 using OpenAPI Generator v7.15.0
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file canva_connect_api-1.0.0.tar.gz.
File metadata
- Download URL: canva_connect_api-1.0.0.tar.gz
- Upload date:
- Size: 214.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8735e3af3c2c65f6a631e39f161b9111be994c7eff52a4a1e2a78d40050d033f
|
|
| MD5 |
ebc4182a09b8cd6a42da99be9239c1b2
|
|
| BLAKE2b-256 |
a76c2b5fec91b2fa483bee3777fe3711c0e441caa2362592849bedaca4da3680
|
File details
Details for the file canva_connect_api-1.0.0-py3-none-any.whl.
File metadata
- Download URL: canva_connect_api-1.0.0-py3-none-any.whl
- Upload date:
- Size: 353.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
cc9c848c0225ba4e23cc239894947933f27a2bf837da0d286b9ded9979bbefad
|
|
| MD5 |
7a62cb8eee8699a501218a2481382411
|
|
| BLAKE2b-256 |
4a69b6bb2e9c7853e5ab9dddb7235833c2ac323c1a8afe5aea90ff4bf6fce659
|