Skip to main content

Archetype Python Library

The Archetype Python library provides convenient access to the Archetype API from applications written in Python. It includes a pre-defined set of classes for API resources that initialize themselves dynamically from API responses which makes it compatible with a wide range of versions of the Archetype API.

The SDK has everything you need to build and manage API subscriptions, usage-based billing, tracking metered usage, issue volume based discounts, graduated pricing models and more.

About Archetype

Archetype is the revenue infrastruce that make API monetization quick and painless. It works by integrating powerful, reliable purchase server with cross-platform support. Our open-source framework provides a backend and a wrapper around payment processors like Stripe to save engineers months from having to build custom billing infrastructure for their APIs.

Whether you are building a new API or already have millions of customers, you can use Archetype to:

Sign up to get started.

Documentation

If looking to use our APIs directly, the API reference is here.

With Archetype, you can keep track of all your app transactions in one place — whether your customers are charged through iOS, Android, or the web. As the single source of truth for your API business, we make sure your customers' subscription status is always up to date.

Installation

Explore the docs and view the quickstart guide

You don't need this source code unless you want to modify the package. If you just want to use the package, just run:

pip install --upgrade archetypesdk

Requirements

Python 3.6+ (PyPy supported)

Usage

The library needs to be configured with your account's app_id and secret key which is available in your Archetype Dashboard. Set archetype.app_id and archetype.secret_key to their values:

import archetypesdk as archetype

archetype.app_id = "ARCHETYPE_APP_ID"
archetype.secret_key = "ARCHETYPE_SECRET_KEY"

CUSTOM_CUSTOMER_UID = "XXX"

# list customers
customers = archetype.Customer.All()

# print the first customer's email
print(customers[0]["email"])

# retrieve specific Customer
customer = archetype.Customer.Retrieve(CUSTOM_CUSTOMER_UID)

# print that customer's email
print(customer["email"])

## Track a Metered Usage

archetype.BillableMetric.LogUsage(
    custom_uid=CUSTOM_CUSTOMER_UID, 
    billable_metric_id=BILLABLE_METRIC_ID, 
    used_amount=AMOUNT,
)


# Authorize a Flask Request with Archetype Middelware

from flask import Flask

app = Flask(__name__)

@app.route("/a", methods=["GET", "POST"])
@archetype.Auth
def auth_test_url():
    return jsonify({"response": "success!"}), 200

# Authorize a Django Request with Archetype Middelware

@archetype.Auth
def sensitive_fbv(request, *args, **kwargs):
    return HttpResponse()

# Authorize a FastAPI Request with Archetype Middelware
from archetypesdk.fastapi import authorized

@app.get("/authorize")
async def hello_world(is_authorized = Depends(authorized)):
    return {"response": "Success"}

You can leverage the SDK to create and configure billable metrics, products, token management, authorization and more. Check out the docs for more examples and use cases.

Metadata

Release files for archetypesdk 1.0.16

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

Source distribution (sdist)

Source distribution for archetypesdk 1.0.16
File Size Uploaded
archetypesdk-1.0.16.tar.gz 23.5 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for archetypesdk 1.0.16
File Interpreter ABI Platform
archetypesdk-1.0.16-py3-none-any.whl Python 3 none any Details

Total release size: 50.2 kB

Release files / archetypesdk-1.0.16.tar.gz

Download URL archetypesdk-1.0.16.tar.gz
Size 23.5 kB
Tags Source
SHA-256 checksum
How to use checksums
dae89faaeff6fe0335b54ebb56add3d6ac52264bf51a5be3dc6da658cdfc0cc4
BLAKE2b-256 checksum
How to use checksums
ae0774fb2f1cbe4e848aadcbb9e02c02a4d089ef621fcefca032b5f9473b7b7d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.10.8

Release files / archetypesdk-1.0.16-py3-none-any.whl

Download URL archetypesdk-1.0.16-py3-none-any.whl
Size 26.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
cd90086d84636aef5b0caef5ef577dc371c701c4da19a6d8b016c947e7a54318
BLAKE2b-256 checksum
How to use checksums
ba48cef4ac244129e985ec0efaf11b9a1b2684fecbd0e3033f713af3a9b06dec
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.10.8

Release history Release notifications | RSS feed

This release

1.0.16 This release

2 release files

1.0.15

2 release files

1.0.14

2 release files

1.0.13

2 release files

1.0.9

2 release files

1.0.8

2 release files

1.0.7

2 release files

1.0.6

2 release files

1.0.5

2 release files

1.0.4

2 release files

1.0.3

2 release files

1.0.2

2 release files

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