Skip to main content

PyPI t

django-walletpass

This application implements the creation of signed .pkpass files and API endpoints for pass registration, updates and logging.

Features

  • Build .pkpass with the PassBuilder class
  • Sign .pkpass with SMIME (as apple describes in their documentation)
  • Server implementation for store, registration, update and logging
  • Push notifications (APNs) on pass update
  • Individual storage backend setting
  • Support for mime-type upload using django-storages S3

Requirements

  • Django >=3.2.9
  • Python >= 3.10
  • pyca/cryptography (for .pkpass SMIME sign)
  • djangorestframework >= 3.8

Getting Started

Install

$ pip install django-walletpass

Configure

Add 'django_walletpass' to you installed apps in the settings.py file.

Load the content of your cert.pem and key.pem in your settings.py file. This is required for signing the .pkpass file.

WALLETPASS = {
    'CERT_PATH': 'path/to/your/cert.pem',
    'KEY_PATH': 'path/to/your/key.pem',
    # (None if isn't protected)
    # MUST be in bytes-like
    'KEY_PASSWORD': b'1234',
}

Add extra needed conf to your settings.py file.

WALLETPASS = {
    'CERT_PATH': 'path/to/your/cert.pem',
    'KEY_PATH': 'path/to/your/key.pem',
    # (None if isn't protected)
    # MUST be in bytes-like
    'KEY_PASSWORD': b'1234',

    'PASS_TYPE_ID': 'pass.io.develat.devpubs.example',
    'TEAM_ID': '123456',
    'SERVICE_URL': 'https://example.com/passes/',
}

Add token JWT config data to allow APNs push:

WALLETPASS = {
    'PUSH_AUTH_STRATEGY': 'token',
    'TOKEN_AUTH_KEY_PATH': 'path/to/your/key.p8',
    'TOKEN_AUTH_KEY_ID': 'key_id',

    'PASS_TYPE_ID': 'pass.io.develat.devpubs.example',
    'TEAM_ID': '123456',
    'SERVICE_URL': 'https://example.com/passes/',
}

You should also import the urls into your site urls.

urlpatterns = [
    url(r'^api/passes/', include('django_walletpass.urls')),

django-walletpass signals certain events that might come handy in your application.

from django_walletpass.classviews import PASS_REGISTERED, PASS_UNREGISTERED

@receiver(PASS_REGISTERED)
def pass_registered(sender, **kwargs):
    pass

@receiver(PASS_UNREGISTERED)
def pass_unregistered(sender, **kwargs):
    pass

Signal TOKEN_UNREGISTERED has a default handler. It can be disconnected and replaced.

Configure storage and upload path (optional)

Default: DEFAULT_FILE_STORAGE

WALLETPASS_CONF = {
    # Defaults to DEFAULT_FILE_STORAGE
    'STORAGE_CLASS': 'my.custom.storageclass,
    'UPLOAD_TO': 'passes'
    'STORAGE_BACKEND': 's3storage'  # Dj4.2+ only
}

STORAGE_BACKEND is the key of the django settings STORAGES storage config. e.g

STORAGES['s3storage']['BACKEND'] = 'some.s3.backend.class'

Push notifications sandbox (optional)

Default: False

WALLETPASS_CONF = {
    'PUSH_SANDBOX': False,
}

CA certificates path (optional)

WALLETPASS_CONF = {
    # Cert in pem format.
    'APPLE_WWDRCA_PEM_PATH': 'path/to/cert.pem',
}

Redirect to pass url (optional)

Usefull if you are using django-storages and you want to serve your .pkpass files from s3.

Default: False

WALLETPASS_CONF = {
    STORAGE_HTTP_REDIRECT: True,
}

Build and sign passes

Init builder object:

Init empty builder

from django_walletpass.services import PassBuilder
builder = PassBuilder()

Init builder usign a directory as base

from django_walletpass.services import PassBuilder
builder = PassBuilder(directory='/path/to/your.pass/')

If the base directory contains a pass.json it will be loaded, but remember that required attributes of pass.json will be overwritten during build process using this values:

{
    "passTypeIdentifier": WALLETPASS_CONF['PASS_TYPE_ID'],
    "serialNumber": secrets.token_urlsafe(20),
    "teamIdentifier": WALLETPASS_CONF['TEAM_ID'],
    "webServiceURL": WALLETPASS_CONF['SERVICE_URL'],
    "authenticationToken": crypto.gen_random_token(),
}

Handle pass.json data

To handle pass.json data, there is a dict inside your builder instance, you can manage it like a normal python dictionary.

Update some attrs:

builder.pass_data.update({
  "barcode": {
    "message": "123456789",
    "format": "PKBarcodeFormatPDF417",
    "messageEncoding": "iso-8859-1"
  },
  "organizationName": "Organic Produce",
  "description": "Organic Produce Loyalty Card",
})

Update one attr:

builder.pass_data['description'] = "Organic Produce Loyalty Card"

Overwrite automatically generated required attribute values

builder.pass_data_required.update({
    "passTypeIdentifier": "customvalue",
    "serialNumber": "customvalue",
    "teamIdentifier": "customvalue",
    "webServiceURL": "customvalue",
    "authenticationToken": "customvalue",
})

you can overwrite individual attributes:

builder.pass_data_required.update({
    "serialNumber": "customvalue",
})
builder.pass_data_required['serialNumber] = 'cutomvalue'

Add extra files

file_content = open('myfile', 'rb').read()
builder.add_file('image.png', file_content)

You can also add files to directories:

file_content = open('myfile', 'rb').read()
builder.add_file('en.lproj/pass.strings', file_content)

Build .pkpass

Build the content of .pkpass

pkpass_content = builder.build()

Write to file:

pkpass_file = open('mypass.pkpass', 'wb')
pkpass_file.write(pkpass_content)

Save to new record in DB:

pass_instance = builder.write_to_model()
pass_instance.save()

Save to existent record in DB:

builder.write_to_model(pass_instance)
pass_instance.save()

Load .pkpass from DB and update

builder = PassBuilder.read_from_model(pass_instance)
builder.pass_data.update({'field': 'value'})
builder.build()
builder.save_to_db(pass_instance)

Run tests locally

Checkout source and run from source root directory

docker run -it --rm -v "$(pwd):/app" python:3.8 bash -c "cd /app; python setup.py install; ./example/manage.py test django_walletpass"

Metadata

Release files for django-walletpass 5.0.1

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

Source distribution (sdist)

Source distribution for django-walletpass 5.0.1
File Size Uploaded Provenance Actions
django_walletpass-5.0.1.tar.gz 24.8 kB Without provenance Details for django_walletpass-5.0.1.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for django-walletpass 5.0.1
File Interpreter ABI Platform Actions
django_walletpass-5.0.1-py3-none-any.whl Python 3 none any Details for django_walletpass-5.0.1-py3-none-any.whl

Total release size: 55.3 kB

Release files / django_walletpass-5.0.1.tar.gz

Download URL django_walletpass-5.0.1.tar.gz
Size 24.8 kB
Tags Source
SHA-256 checksum
How to use checksums
cdcead9acb159dfc81c50a6b611ec000bd9fb4cf4689fbe7ac23dd36b7f26541
BLAKE2b-256 checksum
How to use checksums
fb5e039c0d6b6d19050193b11aaea99eff332c9fce8d07d4b765a30388ae6eed
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.12.7

Release files / django_walletpass-5.0.1-py3-none-any.whl

Download URL django_walletpass-5.0.1-py3-none-any.whl
Size 30.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
448d2108674be4c88fdf2d43c74c7906519d127c006abbe78b276bc245c3a80d
BLAKE2b-256 checksum
How to use checksums
11a4a5152158f173ef08c862260702ac951a8b59a24037101f0cea4088bdb15e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.12.7

Security for django-walletpass 5.0.1

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.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

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