Python client for the Airtable API providing comprehensive database operations, ORM functionality, enterprise features, and testing utilities
—
File upload and attachment management with support for multiple attachment fields, content type detection, and URL-based attachments.
Upload files directly to Airtable attachment fields with automatic content type detection and metadata handling.
def upload_attachment(self, record_id: str, field: str, filename: str,
content: Optional[bytes] = None,
content_type: Optional[str] = None) -> dict:
"""
Upload file to attachment field.
Parameters:
- record_id: Record ID to add attachment to
- field: Attachment field name or ID
- filename: File path or name for the attachment
- content: File content as bytes (reads from filename if None)
- content_type: MIME type (auto-detected if None)
Returns:
Dict with complete attachment field value including new attachment
"""from pyairtable import Api
api = Api('your_token')
table = api.table('base_id', 'table_name')
# Upload file from disk
result = table.upload_attachment(
'rec1234567890abcde',
'Attachments',
'/path/to/document.pdf'
)
# Upload from memory with custom content type
with open('/path/to/image.jpg', 'rb') as f:
content = f.read()
result = table.upload_attachment(
'rec1234567890abcde',
'Photos',
'custom_name.jpg',
content=content,
content_type='image/jpeg'
)
# URL-based attachments (create record with attachment URLs)
record = table.create({
'Name': 'Document Record',
'Files': [
{'url': 'https://example.com/doc.pdf', 'filename': 'document.pdf'},
{'url': 'https://example.com/img.png'} # filename auto-detected
]
})Install with Tessl CLI
npx tessl i tessl/pypi-pyairtable