Skip to content

useautumn/autumn-py

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

autumn-py

The Python SDK for Autumn's REST API.

PyPI - Version pypi Discord

Documentation

The Python SDK's documentation can be found on ReadTheDocs.

Features

  • Easily mount Autumn's routes onto your Python backend.
  • Support for synchronous and asynchronous contexts.
  • Fully typed.

Installation

Note

Python 3.9+ is required.

pip install autumn-py

If you want async support, you need to install aiohttp.

pip install aiohttp

# Optionally
pip install aiohttp[speedups]

# You can also install it via the "aio" optional dependency.
pip install autumn-py[aio]

Warning

This version of the SDK is not available on PyPi yet. Please install it directly from this repo.

Quickstart

import asyncio
from autumn import Autumn

# First, initialize a client.
autumn = Autumn(token="am_sk_test_XESp2wyPE...")

async def main():
    # Attach a customer to a product
    await autumn.attach(
        customer_id="john_doe",
        product_id="chat_messages",
    )

    # Check if the customer has access to the product
    check = await autumn.check(
        customer_id="john_doe",
        product_id="chat_messages",
    )
    if check.allowed is True:
        print("Sending chat message...")

    # Once the customer uses a chat message:
    await autumn.track(
        customer_id="john_doe",
        feature_id="chat_messages",
        value=1,
    )

    # Let's say the customer has run out of chat messages.
    check = await autumn.check(
        customer_id="john_doe",
        product_id="chat_messages",
    )
    if check.allowed is False:
        print("Customer has run out of chat messages.")

asyncio.run(main())

Synchronous Usage

import autumn

# First, initialize a client.
client = autumn.Client(token="am_sk_test_XESp2wyPE...")

# Attach a customer to a product
client.attach(
    customer_id="john_doe",
    product_id="chat_messages",
)

# Check if the customer has access to the product
check = client.check(
    customer_id="john_doe",
    product_id="chat_messages",
)
if check.allowed is True:
    print("Sending chat message...")

# Once the customer uses a chat message:
client.track(
    customer_id="john_doe",
    feature_id="chat_messages",
    value=1,
)

# Let's say the customer has run out of chat messages.
check = client.check(
    customer_id="john_doe",
    product_id="chat_messages",
)
if check.allowed is False:
    print("Customer has run out of chat messages.")

License

autumn-py is distributed under the terms of the MIT license.

Authors

Originally written by @justanotherbyte.

Maintained by @johnyeocx and @justanotherbyte.

About

The Python SDK for Autumn's REST API.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages