Etsy API Client Library for Python
Project description
Etsy API Client Library for Python
Table of Contents
- Overview
- Features
- Requirements
- Installation
- Quick Start
- Usage Examples
- API Resources
- Error Handling
- Environment Configuration
- Project Structure
- Contributing
- Support
- License
- Changelog
Overview
A comprehensive Python client library for the Etsy API v3, providing a modern, type-safe interface for interacting with the Etsy marketplace. This SDK simplifies OAuth 2.0 authentication, automatic token refresh, and provides complete coverage of Etsy's API endpoints.
Features
โจ Complete API Coverage - Full support for Etsy API v3 endpoints including:
- Listings management (create, update, delete, search)
- Shop operations (sections, policies, production partners)
- Receipt and transaction handling
- Shipping profiles and destinations
- Product taxonomy and attributes
- File, image, and video uploads
- Reviews and payment processing
๐ Robust Authentication - OAuth 2.0 with PKCE support:
- Secure authorization code flow
- Automatic token refresh before expiry
- Custom token synchronization callbacks
- Session management with timezone-aware expiry handling
๐๏ธ Developer-Friendly Architecture:
- Type-safe request/response models using dataclasses
- Comprehensive enum definitions for API parameters
- Consistent error handling with detailed exceptions
- Rate limiting information in responses
- Clean separation of concerns with resource-based structure
โก Production Ready:
- Built-in retry logic for failed requests
- Configurable environments (production/staging)
- Extensive error handling and validation
- Support for file uploads and multipart requests
Requirements
- Python 3.10 or higher
- An Etsy App API Key (get one at Etsy Developers)
Installation
Install from PyPI
pip install etsy-python
Install from Source
git clone https://github.com/amitray007/etsy-python-sdk.git
cd etsy-python-sdk
pip install -e .
Dependencies
The SDK requires:
requests>=2.32.2- HTTP client libraryrequests-oauthlib>=1.3.1- OAuth 2.0 support
Quick Start
1. Authentication Setup
from etsy_python.v3.auth.OAuth import EtsyOAuth
# Initialize OAuth client
oauth = EtsyOAuth(
keystring="your_api_key",
redirect_uri="http://localhost:8000/callback",
scopes=["listings_r", "listings_w", "shops_r", "shops_w"]
)
# Get authorization URL
auth_url, state = oauth.get_auth_code()
print(f"Visit this URL to authorize: {auth_url}")
# After user authorizes, set the authorization code
oauth.set_authorisation_code(code="auth_code_from_callback", state=state)
# Get access token
token_data = oauth.get_access_token()
2. Initialize Client Session
from datetime import datetime
from etsy_python.v3.resources.Session import EtsyClient
# Create client with tokens
client = EtsyClient(
keystring="your_api_key",
access_token=token_data["access_token"],
refresh_token=token_data["refresh_token"],
expiry=datetime.utcnow() + timedelta(seconds=token_data["expires_in"])
)
3. Make API Calls
from etsy_python.v3.resources.Listing import ListingResource
from etsy_python.v3.enums.Listing import State, SortOn, SortOrder
# Initialize resource
listing_resource = ListingResource(session=client)
# Get active listings for a shop
response = listing_resource.get_listings_by_shop(
shop_id=12345,
state=State.ACTIVE,
limit=25,
sort_on=SortOn.CREATED,
sort_order=SortOrder.DESC
)
print(f"Found {len(response.message['results'])} listings")
Usage Examples
Managing Listings
from etsy_python.v3.models.Listing import CreateDraftListingRequest
from etsy_python.v3.enums.Listing import WhoMade, WhenMade
# Create a draft listing
draft_listing = CreateDraftListingRequest(
title="Handmade Ceramic Mug",
description="Beautiful handcrafted ceramic mug",
price=25.00,
quantity=10,
who_made=WhoMade.I_DID,
when_made=WhenMade.MADE_TO_ORDER,
taxonomy_id=1234,
tags=["ceramic", "mug", "handmade"]
)
response = listing_resource.create_draft_listing(
shop_id=12345,
listing=draft_listing
)
Working with Receipts
from etsy_python.v3.resources.Receipt import ReceiptResource
from etsy_python.v3.models.Receipt import CreateReceiptShipmentRequest
receipt_resource = ReceiptResource(session=client)
# Get shop receipts
receipts = receipt_resource.get_shop_receipts(
shop_id=12345,
limit=50
)
# Create shipment for a receipt
shipment_request = CreateReceiptShipmentRequest(
tracking_number="1Z999AA10123456784",
carrier_name="USPS",
notification_sent=True
)
receipt_resource.create_receipt_shipment(
shop_id=12345,
receipt_id=67890,
shipment=shipment_request
)
Uploading Images
from etsy_python.v3.resources.ListingImage import ListingImageResource
from etsy_python.v3.models.Listing import UploadListingImageRequest
image_resource = ListingImageResource(session=client)
# Upload image to listing
with open("product_photo.jpg", "rb") as image_file:
upload_request = UploadListingImageRequest(
image=image_file,
alt_text="Front view of ceramic mug"
)
response = image_resource.upload_listing_image(
shop_id=12345,
listing_id=67890,
image=upload_request
)
Handling Shipping Profiles
from etsy_python.v3.resources.ShippingProfile import ShippingProfileResource
from etsy_python.v3.models.ShippingProfile import CreateShopShippingProfileRequest
from etsy_python.v3.enums.ShippingProfile import ProcessingTimeUnit
shipping_resource = ShippingProfileResource(session=client)
# Create shipping profile
profile_request = CreateShopShippingProfileRequest(
title="Standard Shipping",
processing_time_value=3,
processing_time_unit=ProcessingTimeUnit.BUSINESS_DAYS,
origin_country_iso="US",
primary_cost=5.00,
secondary_cost=2.00
)
response = shipping_resource.create_shop_shipping_profile(
shop_id=12345,
profile=profile_request
)
Token Management with Callback
def save_tokens_to_database(access_token, refresh_token, expiry):
"""Custom function to persist tokens"""
# Your database logic here
pass
# Initialize client with token sync callback
client = EtsyClient(
keystring="your_api_key",
access_token=access_token,
refresh_token=refresh_token,
expiry=expiry,
sync_refresh=save_tokens_to_database
)
# Tokens will be automatically refreshed and saved when expired
API Resources
The SDK provides comprehensive coverage of Etsy API v3 resources:
Core Resources
- Listing - Create, read, update, delete listings
- Shop - Manage shop information and settings
- Receipt - Handle orders and transactions
- ReceiptTransactions - Individual transaction details
- User - User profiles and addresses
- UserAddress - User address management
- ShippingProfile - Configure shipping options and destinations
Media Resources
- ListingImage - Upload and manage listing images
- ListingVideo - Upload and manage listing videos
- ListingFile - Digital file management
- ListingVariationImages - Variation-specific images
Commerce Resources
- ListingInventory - Stock and SKU management
- ListingOffering - Product offering details
- ListingProduct - Product variant management
- Payment - Payment processing
- PaymentLedgerEntry - Payment ledger entries
- Review - Customer reviews management
Shop Management
- ShopSection - Organize listings into sections
- ShopReturnPolicy - Define return policies
- ShopProductionPartner - Manage production partners
- HolidayPreferences - Shop holiday schedule
- ProcessingProfile - Processing time profiles
Taxonomy & Translation
- BuyerTaxonomy / SellerTaxonomy - Product categories and attributes
- ListingTranslation - Listing localization
- Miscellaneous - Ping and other utility endpoints
Error Handling
The SDK provides detailed error information through custom exceptions:
from etsy_python.v3.exceptions.RequestException import RequestException
try:
response = listing_resource.get_listing(listing_id=12345)
except RequestException as e:
print(f"Error Code: {e.code}")
print(f"Error Message: {e.error}")
print(f"Error Description: {e.type}")
# Rate limit information (if available)
if e.rate_limits:
print(f"Daily Limit: {e.rate_limits.limit_per_day}")
print(f"Remaining Today: {e.rate_limits.remaining_today}")
Environment Configuration
Configure the SDK environment using environment variables:
# Set environment (defaults to PROD)
export ETSY_ENV=PROD
Project Structure
etsy-python-sdk/
โโโ etsy_python/
โ โโโ _version.py # Single source of truth for version
โ โโโ v3/
โ โโโ auth/ # OAuth 2.0 PKCE authentication
โ โโโ common/ # Shared utilities and HTTP constants
โ โโโ enums/ # Type-safe API parameter constants
โ โโโ exceptions/ # Custom exceptions with rate limit info
โ โโโ models/ # Request data models with validation
โ โโโ resources/ # ~28 API endpoint resource classes
โโโ tests/ # pytest test suite
โ โโโ fixtures/ # Shared test fixtures and mock responses
โโโ scripts/ # Maintenance and release scripts
โโโ specs/ # OAS spec files and audit reports
โโโ .github/
โ โโโ workflows/ # CI/CD and PR automation
โ โโโ CODEOWNERS # Required reviewers for sensitive files
โโโ setup.py # Package configuration
โโโ requirements-dev.txt # Development/testing dependencies
โโโ README.md # Documentation
Contributing
We welcome contributions! Please see our Contributing Guidelines for details.
Automatic Versioning
This project uses automatic semantic versioning based on commit messages:
- Commits with
breaking:orBREAKING CHANGEโ Major version bump (1.0.0 โ 2.0.0) - Commits with
feat:or containingfeatureโ Minor version bump (1.0.0 โ 1.1.0) - All other commits โ Patch version bump (1.0.0 โ 1.0.1)
The version is automatically bumped when changes are pushed to the master branch, and the package is automatically published to PyPI.
Skipping CI/CD
To skip the automatic versioning and publishing workflow, include one of these phrases in your commit message:
[skip ci][ci skip]skip ci[no ci]
Example:
git commit -m "docs: update README [skip ci]"
Manual Release (for maintainers)
For local testing or manual releases:
# Install development dependencies
pip install -e .
# Create a patch release
python scripts/release.py patch
# Create a minor release
python scripts/release.py minor
# Create a major release
python scripts/release.py major
# Dry run (local only, no push)
python scripts/release.py patch --no-push
Development Setup
- Fork the repository
- Clone your fork:
git clone https://github.com/yourusername/etsy-python-sdk.git cd etsy-python-sdk
- Create a virtual environment:
python -m venv venv source venv/bin/activate # On Windows: venv\Scripts\activate
- Install dependencies:
pip install -r etsy_python/requirements.txt pip install -r requirements-dev.txt
- Run the test suite:
pytest -v pytest --cov=etsy_python --cov-report=term-missing
- Create a feature branch:
git checkout -b feature/your-feature-name
- Make your changes and commit:
git commit -m "feat: add your feature"
- Push and create a pull request
CI on Pull Requests
Pull requests automatically trigger:
- pr-tests.yml โ Runs the full test suite with coverage reporting (posts/updates a comment on the PR)
- pr-coverage.yml โ SDK coverage audit against the Etsy OAS spec (triggered by the
sdk-checklabel)
Support
- Documentation: GitHub Wiki
- Issues: GitHub Issues
- Etsy API Docs: developers.etsy.com
License
This project is licensed under the MIT License - see the LICENSE file for details.
Changelog
See Releases for full changelog.
Made with โค๏ธ for the Etsy developer community
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 etsy_python-1.1.5.tar.gz.
File metadata
- Download URL: etsy_python-1.1.5.tar.gz
- Upload date:
- Size: 33.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c52e8cfa1be76f018ceccffc0807f773b44772a729c9fd780b092845e23dc660
|
|
| MD5 |
491851b6b11c32477d42596282fbcb40
|
|
| BLAKE2b-256 |
8f79a8fa9da2dae315327534144a6fbd6d489a29085ad332bebc307b9180ee00
|
Provenance
The following attestation bundles were made for etsy_python-1.1.5.tar.gz:
Publisher:
python-publish.yml on amitray007/etsy-python-sdk
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
etsy_python-1.1.5.tar.gz -
Subject digest:
c52e8cfa1be76f018ceccffc0807f773b44772a729c9fd780b092845e23dc660 - Sigstore transparency entry: 1199377009
- Sigstore integration time:
-
Permalink:
amitray007/etsy-python-sdk@466e5e157afbfe487910ef23a117c3a2ee892187 -
Branch / Tag:
refs/heads/master - Owner: https://github.com/amitray007
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
python-publish.yml@466e5e157afbfe487910ef23a117c3a2ee892187 -
Trigger Event:
push
-
Statement type:
File details
Details for the file etsy_python-1.1.5-py3-none-any.whl.
File metadata
- Download URL: etsy_python-1.1.5-py3-none-any.whl
- Upload date:
- Size: 47.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
335a5c9240defc2fd86339e86285f69dfb3831ab630b69c87839ddcef4cfa0dc
|
|
| MD5 |
1573e26cef8c8127867dd21251034898
|
|
| BLAKE2b-256 |
c1d59a7456519bf13d555ff69a6acdc17bb04ec5cd74004180cf81e5cdd2803a
|
Provenance
The following attestation bundles were made for etsy_python-1.1.5-py3-none-any.whl:
Publisher:
python-publish.yml on amitray007/etsy-python-sdk
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
etsy_python-1.1.5-py3-none-any.whl -
Subject digest:
335a5c9240defc2fd86339e86285f69dfb3831ab630b69c87839ddcef4cfa0dc - Sigstore transparency entry: 1199377052
- Sigstore integration time:
-
Permalink:
amitray007/etsy-python-sdk@466e5e157afbfe487910ef23a117c3a2ee892187 -
Branch / Tag:
refs/heads/master - Owner: https://github.com/amitray007
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
python-publish.yml@466e5e157afbfe487910ef23a117c3a2ee892187 -
Trigger Event:
push
-
Statement type: