pcperini-historic / PyPKPass

A series of Python objects for the construction, management, and serialization of iOS PassKit passes.
21 stars 7 forks source link

PyPKPass

A series of Python objects for the construction, management, and serialization of iOS PassKit passes.

Coming Soon

Builtin support for transporting PKPasses. Pre-rolled Flask-based support for PassKit webServices.

A Certified Mess

Like all Apple endeavors, the amount of signature hoops one must jump through to create a .pkpass is immense. However, PyPKPass attempts to reduce the amount of strife on you by requiring only 1 file for certification.

The private key of your pass type, in .p12 format. This can be gotten by opening Keychain Access.app, finding your Pass Type ID certificate (which you made here, right?), and exporting the PRIVATE KEY as a .p12 file.

You'll need this files for signing passes. Optionally, you can provide your own WWDR certificate. If you have any problems, Google around (there's plenty of tutorials out there) or feel free to email me.

PKPass

init

__init__(self, passTypeIdentifier, serialNumber)

Initializes a new PKPass object with the given passTypeIdentifier and serialNumber.

addRelevantLocation

addRelevantLocation(self, latitude, longitude, altitude = 0, relevantText = None)

Creates a new PKPassLocation and adds it to this PKPass's locations list.

setBarcode

setBarcode(self, message, format = "PKBarcodeFormatQR", messageEncoding = "iso-8859-1", altText = None)

Creates a new PKPassBarcode and sets it to this PKPass's barcode variable.

addField

addField(self, destination, key, value, label, changeMessage, textAlignment)

Creates a new PKPassField and adds it to destination.

addHeaderField

addHeaderField(self, key, value, label = None, changeMessage = None, textAlignment = "PKTextAlignmentNatural")

Calls addField with this PKPass's headerFields variable as destination.

addPrimaryField

addPrimaryField(self, key, value, label = None, changeMessage = None, textAlignment = "PKTextAlignmentNatural")

Calls addField with this PKPass's primaryFields variable as destination.

addSecondaryField

addSecondaryField(self, key, value, label = None, changeMessage = None, textAlignment = "PKTextAlignmentNatural")

Calls addField with this PKPass's secondaryFields variable as destination.

addAuxiliaryField

addAuxiliaryField(self, key, value, label = None, changeMessage = None, textAlignment = "PKTextAlignmentNatural")

Calls addField with this PKPass's auxiliaryFields variable as destination.

addBackField

addBackField(self, key, value, label = None, changeMessage = None, textAlignment = "PKTextAlignmentNatural")

Calls addField with this PKPass's backFields variable as destination.

serialized

serialized(self)

Returns a JSON-valid dict object representing this PKPass. None values will not be serialized.

pack

pack(self, outputLocation)

Creates a package-style directory containing this pass, serialized into pass.json, its icon files, and its logo files.

sign

sign(self, certLocation, certPassword, outputLocation, wwdrCertLocation = 'WWDR.pem')

Creates a signed, compressed .pkpass file containing this pass' package.

--

PKBoardingPass (PKPass)

--

PKCoupon (PKPass)

--

PKEventTicket (PKPass)

--

PKStoreCard (PKPass)

--

PKPassBarcode

init

__init__(self, message, format = "PKBarcodeFormatQR", messageEncoding = "iso-8859-1", altText = None)

Initializes a new PKPassBarcode object with the given message, format, messageEncoding, and altText.

serialized

serialized(self)

Returns a JSON-valid dict object representing this PKPassBarcode. None values will not be serialized.

--

PKPassField

init

__init__(self, key, value, label = None, changeMessage = None, textAlignment = "PKTextAlignmentNatural")

Initializes a new PKPassField object with the given key, value, label, changeMessage, and textAlignment.

setDateStyle

setDateStyle(self, dateStyle = "PKDateStyleFull", timeStyle = "PKTimeStyleFull", isRelative = True)

Adds date styling information to this PKPassField.

setNumberStyle

setNumberStyle(self, currencyCode = "USD", numberStyle = "PKNumberStyleDecimal")

Adds number styling information to this PKPassField.

setBalance

setBalance(self, balance)

Sets the balance of this PKPassField. Only appropriate for use with PKStoreCards.

--

PKPassLocation

init

__init__(self, latitude, longitude, altitude = 0, relevantText = None)

Initializes a new PKPassLocation object with the given latitude, longitude, altitude, and relevantText.

serialized

serialized(self)

Returns a JSON-valid dict object representing this PKPassLocation. None values will not be serialized.