The Python SDK for Autumn's REST API.
The Python SDK's documentation can be found on ReadTheDocs.
- Easily mount Autumn's routes onto your Python backend.
- Support for synchronous and asynchronous contexts.
- Fully typed.
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.
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())
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.")
autumn-py
is distributed under the terms of the MIT license.
Originally written by @justanotherbyte.
Maintained by @johnyeocx and @justanotherbyte.