Skip to main content

Django Plugin For memberpress REST API Client

pypi django-memberpress-client memberpress hack.d Lawrence McDaniel

memberpress

A lightweight, performant Django plugin that implements REST api and Webhook integrations for the Wordpress memberpress Pro plugin.

Installation

pip install django-memberpress-client
from django.conf import settings

# required settings
settings.MEMBERPRESS_API_KEY = 'set-me-please'
settings.MEMBERPRESS_API_BASE_URL = 'https://set-me-please.com/'

# optional settings
settings.MEMBERPRESS_API_KEY_NAME = "MEMBERPRESS-API-KEY"
settings.MEMBERPRESS_CACHE_EXPIRATION = 60*60*24
settings.MEMBERPRESS_SENSITIVE_KEYS = [
    "password",
    "token",
    "client_id",
    "client_secret",
    "Authorization",
    "secret",
]

Alternatively, you can rename .env-sample, located in the same folder location as this README.md, to .env:

# required settings
MEMBERPRESS_API_KEY=set-me-please
MEMBERPRESS_API_BASE_URL=https://set-me-please.com

# optional settings
MEMBERPRESS_CACHE_EXPIRATION=3600
MEMBERPRESS_API_KEY_NAME=MEMBERPRESS-API-KEY
MEMBERPRESS_SENSITIVE_KEYS=password,token,client_id,client_secret,Authorization,secret

You'll find the memberpress API Key in the Wordpress admin site. memberpress API Key

Usage

REST API

# from a Python module inside your existing Django project.
from memberpress_client.member import Member

member = Member(username="jsmith")

if member.should_raise_paywall:
    # not a member, free trial has expired, subscription expired,
    # subscription renewal payment transaction declined, etc.
    your_custom_paywall_code()

# and, there is lots more detailed information about the member,
# their subscription status, their recent transactions history,
# and so on...
print(member.is_active_subscription)
print(member.is_trial_subscription)
print(member.latest_transaction.amount)
print(member.recent_subscriptions[0].created_at)
print(member.active_memberships[0].pricing_title)

Webhooks

This plugin listens for events from memberpress' webhooks framework, a Pro 'developer tools' premium option of memberpress. Add a url of the form https://yourdomain.com/mp/api/v1/webhook to the Developer "Webhooks" page. memberpress webhooks

urls:

Django admin console

Developers

quick start

Keep in mind that this code package is intended to install as an add-on to your existing Django project. Therefore, the 'production' settings and requirements intentionally ommit all Django and Django support packages other than those that are unique to this repo. The 'local' settings and requirements compensate for this by including all of the settings and requirements that you'd typically find in 'common' and/or 'production'.

You should be able to follow the normal workflow for setting up a Django project for local development. This substantially consists of the following:

  • rename ./memberpress_client/settings/.env-sample to ./memberpress_client/settings/.env
  • install all service-level dependencies on your local dev machine. This includes MySQL and Redis.
  • clone this repo
  • create and activate a Python virtual environment
  • run make quickstart

Other common dev chores are automated in the Makefile, noting however that some syntax is specific to macOS environments (my sincerest apologies), plus, it assumes that you've installed mysql and redis using homebrew.

class hierarchy

Use these class objects rather than working directly with the memberpress json dicts returned by the api. These class objects include structural and type-checking validations, plus they handle dict value data type conversations for you.

class Memberpress:

    class MemberpressEvent(Memberpress):

    class MemberpressAPIClient(Memberpress):
        class Member(MemberpressAPIClient):
        class Membership(MemberpressAPIClient):
        class Subscriber(MemberpressAPIClient):
        class Transaction(MemberpressAPIClient):

constants

Use these built-in constants rather than working directly with memberpress' dict key string values:

  • MemberpressEvents: discrete list of memberpress event types. The str value exactly matches the event dict key "event".
  • MemberpressEventTypes: discrete list of memberpress event_types
from memberpress_client.constants import MemberpressEvents

print(MemberpressEvents.AFTER_CC_EXPIRES_REMINDER)
after-cc-expires-reminder

print(MemberpressEvents.AFTER_MEMBER_SIGNUP_REMINDER)
after-member-signup-reminder

print(MemberpressEvents.LOGIN)
login

print(MemberpressEvents.MEMBER_ACCOUNT_UPDATED)
member-account-updated

print(MemberpressEvents.SUBSCRIPTION_EXPIRED)
subscription-expired
# ...
# ectetera, etcetera, etcetera ...
# ...
print(MemberpressEvents.TRANSACTION_COMPLETED)
transaction-completed

Additionally, note that many of the constants include helper functions. memberpress_client constants

Metadata

Release files for django-memberpress-client 1.0.5

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-memberpress-client 1.0.5
File Size Uploaded Provenance
django_memberpress_client-1.0.5.tar.gz 36.1 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for django-memberpress-client 1.0.5
File Interpreter ABI Platform
django_memberpress_client-1.0.5-py2.py3-none-any.whl Python 3, Python 2 none any Details

Total release size: 83.0 kB

Release files / django_memberpress_client-1.0.5.tar.gz

Download URL django_memberpress_client-1.0.5.tar.gz
Size 36.1 kB
Tags Source
SHA-256 checksum
How to use checksums
500d6c70db8b74f2652ad507b5410f8bf36e50e20d24e13eb116826ccb7644f5
BLAKE2b-256 checksum
How to use checksums
0c9ce9d0a908e37864ff140f31f3306605ccb0a245f7947620a0da226d1be9c7
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.0.0 CPython/3.11.9

Release files / django_memberpress_client-1.0.5-py2.py3-none-any.whl

Download URL django_memberpress_client-1.0.5-py2.py3-none-any.whl
Size 46.9 kB
Tags Python 2 Python 3
SHA-256 checksum
How to use checksums
b6d9d12675b1d041ae955c44c4fc8ae7942648e9f98a0311f1175d6d0291a400
BLAKE2b-256 checksum
How to use checksums
5091bf74ef32c11a8fc55fea838f1507d49028a7751aa4f41ca0160d03709f57
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.0.0 CPython/3.11.9

Security for django-memberpress-client 1.0.5

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