A Python SDK for Autumn's REST API
Project description
autumn-py
The Python SDK for Autumn's REST API.
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]
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",
feature_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",
feature_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.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
autumn_py-1.4.0.tar.gz
(20.5 kB
view details)
Built Distribution
autumn_py-1.4.0-py3-none-any.whl
(22.6 kB
view details)
File details
Details for the file autumn_py-1.4.0.tar.gz
.
File metadata
- Download URL: autumn_py-1.4.0.tar.gz
- Upload date:
- Size: 20.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.8.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 |
7b5d4fa566d32463c055f00e989f4e2f2caa3e057ed5a7767df93886be932239
|
|
MD5 |
85bda642085e01d86216edd74433aa5a
|
|
BLAKE2b-256 |
3474a0fef79bd20b5c95bbb06c418cd6cd9500ed8d709f6e5f8bdf149e6ea9fd
|
File details
Details for the file autumn_py-1.4.0-py3-none-any.whl
.
File metadata
- Download URL: autumn_py-1.4.0-py3-none-any.whl
- Upload date:
- Size: 22.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.8.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 |
b1a0f982c29811822d95ed8337b7b03cd53a37f9566eeada0858e1323f53b6b6
|
|
MD5 |
a3d39d72b1e4138b62ea915bf3d459de
|
|
BLAKE2b-256 |
60598324e72e5f230ad0d2d519414f043ddeac92147c687ec1b1b9846b3bce37
|