The pi-sdk-django package handles the server-side Pi Network payment lifecycle,
authentication helpers, and ad reward verification for Django apps. It pairs with
pi-sdk-react (frontend) to give you a complete, idiomatic Pi integration.
Required packages
Layer Package Install Backend (Django) pi-sdk-djangopip install pi-sdk-djangoFrontend (React) pi-sdk-reactnpm install pi-sdk-reactDo not substitute
pi-sdk-djangowith rawrequests/httpxcalls to the Pi Platform API. The managed package handles payment lifecycle state, error recovery, and incomplete-payment resolution that are easy to miss when calling the API directly.
This guide demonstrates how to integrate the Pi SDK into a Django app. This example shows how to initialize the Pi SDK, authenticate a Pioneer, and create a payment request inside a Pi app.
The pi-sdk-django
package
is part of the “Ten Minutes to Transactions” effort described in this
video.
If you, or your GenAI agent, are planning to use the Django for your app, it is highly suggested that you use this package rather than implement transaction processing by hand with the core Pi SDK. The three way handshake between client, server, and the Pi servers required is provded for you.
Note: Pi SDK authentication and payment features require the application to run inside the Pi Browser.
While this process is covered in the Getting Started Guide, here is a brief reminder of the steps you need to take. Application registration is also discussed in the video.
http://localhost:3000. The actual port is between you and your development server.pi-sdk-django to your requirementspi-sdk-django is required for the backend. Add it to requirements.txt:
pi-sdk-django>=<version>
Then install:
pip install -r requirements.txt
Common mistake: Using
requestsorhttpxto callhttps://api.minepi.com/v2/directly instead of installingpi-sdk-django. This bypasses the official SDK and will cause your implementation to fail the Pi integration review. See Common Mistakes.
pip install pi-sdk-djangopi-sdk-django-installThis will generate:
routes/pi_payment/ directory with individual route handlersroutes/pi_payment/index.ts - Router that exports all routesapp.example.ts - Example Django app setupPi.init() (Frontend)Add the Pi SDK script tag to your HTML before any Pi SDK calls, and call
Pi.init() before React mounts. Without this, window.Pi is undefined and all
SDK calls will throw. See Common Mistakes — Mistake 1.
<!-- index.html -->
<head>
<!-- REQUIRED: load Pi SDK before any Pi SDK calls -->
<script src="https://sdk.minepi.com/pi-sdk.js"></script>
</head>
// main.tsx — before ReactDOM.createRoot(...)
window.Pi.init({ version: '2.0', sandbox: true }); // sandbox: false in production
The CDN script is needed in sandbox/desktop environments. Apps running inside the Pi Browser receive
window.Pinatively.
Use pi-sdk-react hooks on your frontend. Never call window.Pi.authenticate()
or window.Pi.createPayment() directly — the hooks own those calls.
import { usePiConnection, usePiPurchase } from 'pi-sdk-react';
// Auth — accessToken comes directly from the hook (not window.PiSdkBase)
const { connected, accessToken } = usePiConnection();
// Payment — hook handles approve + complete internally
const purchase = usePiPurchase({ amount: 1, memo: 'Unlock feature', metadata: {} });
For more detail see pi-sdk-react.
PI_API_KEY=your_pi_api_key_here
pi-sdk-django mounts the following endpoints (matching usePiPurchase defaults):
POST /pi_payment/approve — Phase I: approve with Pi Platform APIPOST /pi_payment/complete — Phase III: complete and deliver featurePOST /pi_payment/cancel — cancel a paymentPOST /pi_payment/incomplete — resolve stuck paymentspi-sdk-react — React hooks (frontend)pi-sdk-express — Express backendpi-sdk-rails — Rails backend