Skip to content

feat(lib): add files_from_zip helper for skill uploads#1219

Open
lyr408 wants to merge 1 commit intoanthropics:mainfrom
lyr408:feat/files-from-zip-helper
Open

feat(lib): add files_from_zip helper for skill uploads#1219
lyr408 wants to merge 1 commit intoanthropics:mainfrom
lyr408:feat/files-from-zip-helper

Conversation

@lyr408
Copy link

@lyr408 lyr408 commented Mar 4, 2026

Summary

Adds files_from_zip() and async_files_from_zip() helper functions to anthropic.lib, complementing the existing files_from_dir() helper.

Motivation

Currently, uploading a skill from a zip archive requires manually constructing file tuples:

skill = client.beta.skills.create(
    files=[("skill.zip", open("skill.zip", "rb"))],
    ...
)

With this change, users can use a dedicated helper that extracts individual files from the zip:

from anthropic.lib import files_from_zip

skill = client.beta.skills.create(
    files=files_from_zip("financial_analysis_skill.zip"),
    ...
)

Changes

  • src/anthropic/lib/_files.py — Added files_from_zip(), async_files_from_zip(), and internal _read_zip() helper
    • Returns list[FileTypes] (2-tuples) consistent with files_from_dir()
    • Automatically skips directory entries and __MACOSX/ metadata
  • src/anthropic/lib/__init__.py — Exported the new functions
  • tests/lib/test_files.py — 11 tests covering sync/async, edge cases, and mixed tuple format validation
  • examples/skills_from_zip.py — Usage example showing all three file upload patterns, including that the MIME type is optional in file tuples

All changes are in lib/, tests/, and examples/ — directories not affected by the code generator.

- Add files_from_zip() and async_files_from_zip() to anthropic.lib
- Extracts files from zip archives into list[FileTypes] format
- Skips directory entries and __MACOSX/ metadata automatically
- Add comprehensive tests and usage example
- Example demonstrates MIME type is optional in file tuples
@lyr408 lyr408 requested a review from a team as a code owner March 4, 2026 04:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant