Metadata-Version: 2.4
Name: py-pkpass
Version: 1.0.0
Summary: Pkpass file generator
Home-page: https://github.com/GlitchOo/py-pkpass/
Download-URL: https://github.com/GlitchOo/py-pkpass/archive/refs/tags/v1.0.0.tar.gz
Author: GlitchOo
License: The MIT License (MIT)
        
        Copyright (c) 2012 devartis
        
        Permission is hereby granted, free of charge, to any
        person obtaining a copy of this software and associated
        documentation files (the "Software"), to deal in the
        Software without restriction, including without limitation
        the rights to use, copy, modify, merge, publish,
        distribute, sublicense, and/or sell copies of the
        Software, and to permit persons to whom the Software is
        furnished to do so, subject to the following conditions:
        
        The above copyright notice and this permission notice
        shall be included in all copies or substantial portions of
        the Software.
        
        THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
        KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
        WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
        PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS
        OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
        OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
        OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
        SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
        
Classifier: Development Status :: 3 - Alpha
Classifier: Environment :: Other Environment
Classifier: Intended Audience :: Developers
Classifier: Programming Language :: Python :: 3.8
Classifier: Programming Language :: Python :: 3 :: Only
Classifier: Topic :: Software Development :: Libraries :: Python Modules
Description-Content-Type: text/markdown
License-File: LICENSE.txt
Requires-Dist: cryptography>=44.0.1
Requires-Dist: swig; python_version >= "3.10"
Dynamic: author
Dynamic: classifier
Dynamic: description
Dynamic: description-content-type
Dynamic: download-url
Dynamic: home-page
Dynamic: license
Dynamic: license-file
Dynamic: provides-extra
Dynamic: requires-dist
Dynamic: summary

# Py-Pkpass

![Build Status](https://github.com/GlitchOo/py-pkpass/actions/workflows/ci.yml/badge.svg)

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:
```
pip install git+https://github.com/GlitchOo/py-pkpass.git
```

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:
- [Wallet Topic Page](https://developer.apple.com/wallet/)
- [Wallet Developer Guide](https://developer.apple.com/library/ios/documentation/UserExperience/Conceptual/PassKit_PG/index.html#//apple_ref/doc/uid/TP40012195)


## Getting Started

### 1) Get a Pass Type ID

* Visit the [Apple Developer Portal](https://developer.apple.com/) → 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

```shell
# 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](https://www.apple.com/certificateauthority/).

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

## Usage Example

```python
#!/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](http://www.devartis.com).

## Contributors

Martin Bächtold
