Skip to main content

Py-Pkpass

Build Status

This fork is updated to use the latest version of the cryptography library, includes the NFC method, and additional tests for Python v3.8-3.12.

Installing this fork

You can install this fork directly from GitHub or with pip:

pip install git+https://github.com/GlitchOo/py-pkpass.git
pip install py-pkpass

This Python library helps you create Apple Wallet (.pkpass) files (Apple Wallet was previously known as Passbook in iOS 6 to iOS 8).

For more information about Apple Wallet, see the:

Getting Started

1) Get a Pass Type ID

  • Visit the Apple Developer Portal → Certificates, Identifiers & Profiles → Pass Type IDs → New Pass Type ID
  • Select your pass type ID → Configure (Follow steps and download the generated pass.cer file)
  • Use Keychain Access to export a Certificates.p12 file (you need the Apple Root Certificate installed)

2) Generate the certificate and key files (Note: if you are using the latest version of openssl you will need to append -legacy to each command)

# Export certificate from p12 file
openssl pkcs12 -in "Certificates.p12" -clcerts -nokeys -out certificate.pem   

# Export private key from p12 file
openssl pkcs12 -in "Certificates.p12" -nocerts -out private.key

You will be asked for an export password (or export phrase). In the example below, we'll use 123456 as the password.

3) Get the Apple WWDR Certificate

Apple Worldwide Developer Relations (WWDR) Certificate is available at Apple's Certificate Authority.

You can export it from Keychain Access into a .pem file (e.g., wwdr.pem).

Usage Example

#!/usr/bin/env python

from py_pkpass.models import Pass, Barcode, BarcodeFormat, StoreCard

# Create a store card pass type
cardInfo = StoreCard()
cardInfo.addPrimaryField('name', 'John Doe', 'Name')

# Pass certificate information
organizationName = 'Your organization' 
passTypeIdentifier = 'pass.com.your.organization' 
teamIdentifier = 'AGK5BZEN3E'

# Create the Pass object with the required identifiers
passfile = Pass(
    cardInfo, 
    passTypeIdentifier=passTypeIdentifier, 
    organizationName=organizationName, 
    teamIdentifier=teamIdentifier
)

# Set required pass information
passfile.serialNumber = '1234567'
passfile.description = 'Sample Pass'

# Add a barcode - all supported formats: PDF417, QR, AZTEC, CODE128
passfile.barcode = Barcode(
    message='Barcode message',
    format=BarcodeFormat.CODE128,
    altText='Alternate text'
)

# Optional: Add NFC support
nfc_message = "NFCURL:https://example.com/nfc"
encryption_key = "MIIBCgKCAQEAxDvx..."  # Your public encryption key
passfile.nfc_message = nfc_message
passfile.encryption_public_key = encryption_key
passfile.requiresAuthentication = True

# Optional: Set colors
passfile.backgroundColor = "rgb(61, 152, 60)"
passfile.foregroundColor = "rgb(255, 255, 255)"
passfile.labelColor = "rgb(255, 255, 255)"

# Optional: Prevent sharing (disables AirDrop and similar features)
passfile.sharingProhibited = True

# Including the icon and logo is necessary for the passbook to be valid
passfile.addFile('icon.png', open('images/icon.png', 'rb'))
passfile.addFile('logo.png', open('images/logo.png', 'rb'))

# Create and output the Passbook file (.pkpass)
password = '123456'
passfile.create(
    'certificate.pem',
    'private.key',
    'wwdr.pem',
    password,
    'test.pkpass'
)

Testing

You can run the tests with:

python -m pytest -v

Credits

Originally developed by devartis.

Contributors

Martin Bächtold

Metadata

Release files for py-pkpass 1.0.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for py-pkpass 1.0.2
File Size Uploaded
py_pkpass-1.0.2.tar.gz 17.9 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for py-pkpass 1.0.2
File Interpreter ABI Platform
py_pkpass-1.0.2-py3-none-any.whl Python 3 none any Details

Total release size: 36.2 kB

Release files / py_pkpass-1.0.2.tar.gz

Download URL py_pkpass-1.0.2.tar.gz
Size 17.9 kB
Tags Source
SHA-256 checksum
How to use checksums
3ff98faeff82bb97e6ff9dfb75d0e47632c08c21b53ec35e74f5c5e94de876ef
BLAKE2b-256 checksum
How to use checksums
999ad2f135a1071d967d4e9f2abc4db908ede499c78fce8f0c4264f354ba7b73
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.12.9

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Apr 24, 2025.

Transparency log

Release files / py_pkpass-1.0.2-py3-none-any.whl

Download URL py_pkpass-1.0.2-py3-none-any.whl
Size 18.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
76be90fe1f8978c6745f47f3a534c4ed8630db017be90f707d47b3f3266ecc31
BLAKE2b-256 checksum
How to use checksums
e45220213176b27b139df378ba9f760048ddee1ae2b05bbba5820262e78803cf
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.12.9

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Apr 24, 2025.

Transparency log

Release history Release notifications | RSS feed

This release

1.0.2 This release

2 release files

1.0.1

2 release files

1.0.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page