wallet-py3k (Apple Passbook Generator)

0.0.4 · abandoned · verified Thu Apr 16

wallet-py3k is a Python 3 library designed to generate Apple Wallet (.pkpass) files. It is a fork of the `devartis/passbook` library, specifically updated to support Python 3. The library enables programmatic creation of various pass types by assembling content, signing with required Apple certificates, and packaging them into the `.pkpass` format. The last release (0.0.4) was in December 2018, indicating the library is no longer actively maintained.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to create a simple StoreCard pass. It requires pre-generated `.pem` certificate files and `wwdr.pem`, along with `icon.png` and `logo.png` image assets. The `create` method then generates the `.pkpass` file.

import os
from wallet.models import Pass, Barcode, StoreCard

# --- Prerequisites: Generate .pem files from your Apple Pass Type ID certificate ---
# 1. Obtain a Pass Type ID certificate from Apple's developer portal (.p12).
# 2. Convert it to .pem files using OpenSSL (replace "Certificates.p12" with your file):
#    openssl pkcs12 -in "Certificates.p12" -clcerts -nokeys -out certificate.pem
#    openssl pkcs12 -in "Certificates.p12" -nocerts -out key.pem -passout pass:YOUR_KEY_PASSWORD
# 3. Download the Apple Worldwide Developer Relations Certification Authority (WWDR) certificate
#    from Apple's website (http://developer.apple.com/certificationauthority/AppleWWDRCA.cer)
#    and convert it to .pem (e.g., wwdr.pem).

# Ensure these files exist in your working directory or provide full paths.
certificate_path = 'certificate.pem'
key_path = 'key.pem'
wwdr_path = 'wwdr.pem'
key_password = os.environ.get('WALLET_KEY_PASSWORD', 'YOUR_KEY_PASSWORD') # Replace with your actual key password or use env var

# Define pass details
organization_name = 'Your Organization'
pass_type_identifier = 'pass.com.your.organization'
team_identifier = 'AGK5BZEN3E' # Replace with your Apple Team ID

# Create card information
card_info = StoreCard()
card_info.addPrimaryField('name', 'John Doe', 'Name')
card_info.addAuxiliaryField('member_id', '12345', 'Member ID')

# Create the Pass object
passfile = Pass(card_info,
                passTypeIdentifier=pass_type_identifier,
                organizationName=organization_name,
                teamIdentifier=team_identifier)

passfile.serialNumber = '1234567'
passfile.barcode = Barcode(message='Barcode message content', format='PKBarcodeFormatQR')

# Add required assets (icon and logo are mandatory for a valid pass)
# Ensure 'images/icon.png' and 'images/logo.png' exist relative to your script
try:
    with open('images/icon.png', 'rb') as f_icon:
        passfile.addFile('icon.png', f_icon)
    with open('images/logo.png', 'rb') as f_logo:
        passfile.addFile('logo.png', f_logo)
except FileNotFoundError:
    print("Error: icon.png or logo.png not found. Please create 'images/' directory and place the files.")
    exit(1)

output_filename = 'test.pkpass'

# Create and output the Passbook file
try:
    passfile.create(
        certificate_path, 
        key_path, 
        wwdr_path, 
        key_password, 
        output_filename
    )
    print(f"Successfully created {output_filename}")
except Exception as e:
    print(f"Error creating pass: {e}")
    print("Ensure your .pem files are correct and the key_password is accurate.")

view raw JSON →