Skip to main content

Pkpass file generator

Project description

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

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

py_pkpass-1.0.2.tar.gz (17.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

py_pkpass-1.0.2-py3-none-any.whl (18.3 kB view details)

Uploaded Python 3

File details

Details for the file py_pkpass-1.0.2.tar.gz.

File metadata

  • Download URL: py_pkpass-1.0.2.tar.gz
  • Upload date:
  • Size: 17.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for py_pkpass-1.0.2.tar.gz
Algorithm Hash digest
SHA256 3ff98faeff82bb97e6ff9dfb75d0e47632c08c21b53ec35e74f5c5e94de876ef
MD5 8ac2a84048dc874442dc4e90c2208000
BLAKE2b-256 999ad2f135a1071d967d4e9f2abc4db908ede499c78fce8f0c4264f354ba7b73

See more details on using hashes here.

Provenance

The following attestation bundles were made for py_pkpass-1.0.2.tar.gz:

Publisher: python-publish.yml on GlitchOo/py-pkpass

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file py_pkpass-1.0.2-py3-none-any.whl.

File metadata

  • Download URL: py_pkpass-1.0.2-py3-none-any.whl
  • Upload date:
  • Size: 18.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for py_pkpass-1.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 76be90fe1f8978c6745f47f3a534c4ed8630db017be90f707d47b3f3266ecc31
MD5 795adcddfad3dbc1eb1541f3c780a19a
BLAKE2b-256 e45220213176b27b139df378ba9f760048ddee1ae2b05bbba5820262e78803cf

See more details on using hashes here.

Provenance

The following attestation bundles were made for py_pkpass-1.0.2-py3-none-any.whl:

Publisher: python-publish.yml on GlitchOo/py-pkpass

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page