API Reference¶
This page gives an overview of all the public autumn classes, functions and methods. Everything that intended for public use is exposed in the autumn.* or autumn.aio.* namespaces.
Client¶
- class autumn.client.Client(token, *, base_url=None, max_retries=5)[source]¶
The main client class for interacting with the Autumn API.
Example:
import autumn client = autumn.Client(token="your_api_key") # Attach a customer to a product client.attach( customer_id="john_doe", product_id="chat_messages", )
Note
This client should not be used in async contexts. Use
AsyncClientinstead. TheAsyncClientclass is a wrapper around theClientclass that provides async support. It works the same, but you mustawaityour method calls.import asyncio from autumn.aio import ( Client, ) async def main(): client = Client(token="your_api_key") await client.attach( customer_id="john_doe", product_id="chat_messages", ) asyncio.run(main())
The async client requires
aiohttpto be installed. You can install it via:pip install aiohttp.- Parameters:
- attach(customer_id, *, product_id=None, product_ids=None, products=None, success_url=None, force_checkout=False, features=None, entity_id=None, customer_data=None, free_trial=None, options=None, reward=None)[source]¶
Attach a customer to a product.
This function returns an awaitable coroutine when using the
AsyncClientclass.- Parameters:
customer_id (str) – The ID of the customer to attach.
product_id (Optional[str]) – The ID of the product to attach.
product_ids (Optional[List[str]]) – The IDs of the products to attach.
products (Optional[List[AttachProductOptions]]) – The products to attach.
success_url (Optional[str]) – The URL to redirect to after a successful attachment.
force_checkout (bool) – Whether to force the customer to checkout.
features (Optional[List[Feature]]) – The features to attach.
entity_id (Optional[str]) – The ID of the entity to attach.
customer_data (Optional[CustomerData]) – The customer data to attach.
free_trial (Optional[bool]) – Whether to attach a free trial.
options (Optional[List[FeatureOptions]]) – The options to attach.
reward (Optional[str | List[str]]) – The reward to attach. Can pass in an array too.
- Returns:
The response from the API.
- Return type:
- cancel(customer_id, product_id, *, entity_id=None, cancel_immediately=False)[source]¶
Cancel a product for a customer.
- Parameters:
customer_id (str) – The ID of the customer to cancel the product for.
product_id (str) – The ID of the product to cancel.
entity_id (Optional[str]) – The ID of the entity to cancel the product for.
cancel_immediately (bool) – Whether to cancel the product immediately. If false, the product will be cancelled at the end of the billing cycle.
- Returns:
The response from the API.
- Return type:
- check(customer_id, *, product_id=None, feature_id=None, required_balance=1, send_event=False, with_preview=False, entity_id=None, customer_data=None)[source]¶
Check if a customer has access to a product or feature.
This function returns an awaitable coroutine when using the
AsyncClientclass.You must pass either
product_idorfeature_id. Failure to pass one and only one will raise an assertion error.- Parameters:
customer_id (str) – The ID of the customer to check.
product_id (Optional[str]) – The ID of the product to check.
feature_id (Optional[str]) – The ID of the feature to check.
required_balance (Optional[int]) – The required balance to check.
send_event (bool) – Whether to record a usage event with checking access. The
`required_balancefield will be used as the usagevalue.with_preview (bool) – If true, the response will include a
previewobject, which can be used to display information such as a paywall or upgrade confirmation.entity_id (Optional[str]) – If using entity balances (eg, seats), the entity ID to check access for.
customer_data (Optional[CustomerData]) – Additional customer properties. These will be used if the customer’s properties are not already set.
- Returns:
The response from the API.
- Return type:
- checkout(customer_id, *, product_id=None, products=None, success_url=None, force_checkout=False, options=None, entity_id=None, customer_data=None, checkout_session_params=None, reward=None)[source]¶
Checkout a customer for a product.
- Parameters:
customer_id (str) – The ID of the customer to checkout.
product_id (Optional[str]) – The ID of the product to checkout.
products (Optional[List[ProductOptions]]) – The products to checkout.
success_url (Optional[str]) – The URL to redirect to after a successful checkout.
force_checkout (bool) – Whether to force the customer to checkout.
entity_id (Optional[str]) – The ID of the entity to checkout.
customer_data (Optional[CustomerData]) – The customer data to checkout.
reward (Optional[str | List[str]]) – The reward to checkout. Can pass in an array too.
- Return type:
- query(customer_id, feature_id, *, range='30d')[source]¶
Query usage analytics for a customer on a specific feature.
- Parameters:
- Returns:
The response from the API.
- Return type:
- track(customer_id, feature_id=None, *, value=1, entity_id=None, event_name=None, idempotency_key=None, properties=None, customer_data=None)[source]¶
Track a feature usage.
This function returns an awaitable coroutine when using the
AsyncClientclass.- Parameters:
customer_id (str) – The ID of the customer to track.
feature_id (Optional[str]) – The ID of the feature to track. This or the
event_namemust be provided.value (int) – The amount of the feature to deduct.
entity_id (Optional[str]) – The ID of the entity to track.
event_name (Optional[str]) – The name of the event to track.
idempotency_key (Optional[str]) – A unique identifier for the track event. If not provided, the SDK will not generate one - the Autumn API does not expect one.
properties (Optional[Dict[str, Any]]) – Additional properties to track.
customer_data (Optional[CustomerData]) – Additional customer properties. These will be used if the customer’s properties are not already set.
- Returns:
The response from the API.
- Return type:
- class autumn.aio.client.AsyncClient(token, *, base_url=None, max_retries=5, session=None)[source]¶
Bases:
ClientThe
asyncclient class for interacting with the Autumn API.This class is also exposed as
autumn.Autumn.The
AsyncClientautomatically retries requests up to 5 times, exponentially backing off between attempts.Note that session creation is lazy. This means that the
AsyncClientwill not attempt to create a session until the first request is made.- Parameters:
token (str) – The API key to use for authentication.
base_url (Optional[str]) – The base URL of the Autumn API. This is useful when you are self-hosting Autumn and need to point to your own instance.
max_retries (int) – The maximum number of retries to attempt for failed requests.
session (Optional[
ClientSession]) – The session to use for requests. If not provided, a new session will be created lazily.
- attach(customer_id, *, product_id=None, product_ids=None, products=None, success_url=None, force_checkout=False, features=None, entity_id=None, customer_data=None, free_trial=None, options=None, reward=None)¶
Attach a customer to a product.
This function returns an awaitable coroutine when using the
AsyncClientclass.- Parameters:
customer_id (str) – The ID of the customer to attach.
product_id (Optional[str]) – The ID of the product to attach.
product_ids (Optional[List[str]]) – The IDs of the products to attach.
products (Optional[List[AttachProductOptions]]) – The products to attach.
success_url (Optional[str]) – The URL to redirect to after a successful attachment.
force_checkout (bool) – Whether to force the customer to checkout.
features (Optional[List[Feature]]) – The features to attach.
entity_id (Optional[str]) – The ID of the entity to attach.
customer_data (Optional[CustomerData]) – The customer data to attach.
free_trial (Optional[bool]) – Whether to attach a free trial.
options (Optional[List[FeatureOptions]]) – The options to attach.
reward (Optional[str | List[str]]) – The reward to attach. Can pass in an array too.
- Returns:
The response from the API.
- Return type:
- cancel(customer_id, product_id, *, entity_id=None, cancel_immediately=False)¶
Cancel a product for a customer.
- Parameters:
customer_id (str) – The ID of the customer to cancel the product for.
product_id (str) – The ID of the product to cancel.
entity_id (Optional[str]) – The ID of the entity to cancel the product for.
cancel_immediately (bool) – Whether to cancel the product immediately. If false, the product will be cancelled at the end of the billing cycle.
- Returns:
The response from the API.
- Return type:
- check(customer_id, *, product_id=None, feature_id=None, required_balance=1, send_event=False, with_preview=False, entity_id=None, customer_data=None)¶
Check if a customer has access to a product or feature.
This function returns an awaitable coroutine when using the
AsyncClientclass.You must pass either
product_idorfeature_id. Failure to pass one and only one will raise an assertion error.- Parameters:
customer_id (str) – The ID of the customer to check.
product_id (Optional[str]) – The ID of the product to check.
feature_id (Optional[str]) – The ID of the feature to check.
required_balance (Optional[int]) – The required balance to check.
send_event (bool) – Whether to record a usage event with checking access. The
`required_balancefield will be used as the usagevalue.with_preview (bool) – If true, the response will include a
previewobject, which can be used to display information such as a paywall or upgrade confirmation.entity_id (Optional[str]) – If using entity balances (eg, seats), the entity ID to check access for.
customer_data (Optional[CustomerData]) – Additional customer properties. These will be used if the customer’s properties are not already set.
- Returns:
The response from the API.
- Return type:
- checkout(customer_id, *, product_id=None, products=None, success_url=None, force_checkout=False, options=None, entity_id=None, customer_data=None, checkout_session_params=None, reward=None)¶
Checkout a customer for a product.
- Parameters:
customer_id (str) – The ID of the customer to checkout.
product_id (Optional[str]) – The ID of the product to checkout.
products (Optional[List[ProductOptions]]) – The products to checkout.
success_url (Optional[str]) – The URL to redirect to after a successful checkout.
force_checkout (bool) – Whether to force the customer to checkout.
entity_id (Optional[str]) – The ID of the entity to checkout.
customer_data (Optional[CustomerData]) – The customer data to checkout.
reward (Optional[str | List[str]]) – The reward to checkout. Can pass in an array too.
- Return type:
- query(customer_id, feature_id, *, range='30d')¶
Query usage analytics for a customer on a specific feature.
- Parameters:
- Returns:
The response from the API.
- Return type:
- track(customer_id, feature_id=None, *, value=1, entity_id=None, event_name=None, idempotency_key=None, properties=None, customer_data=None)¶
Track a feature usage.
This function returns an awaitable coroutine when using the
AsyncClientclass.- Parameters:
customer_id (str) – The ID of the customer to track.
feature_id (Optional[str]) – The ID of the feature to track. This or the
event_namemust be provided.value (int) – The amount of the feature to deduct.
entity_id (Optional[str]) – The ID of the entity to track.
event_name (Optional[str]) – The name of the event to track.
idempotency_key (Optional[str]) – A unique identifier for the track event. If not provided, the SDK will not generate one - the Autumn API does not expect one.
properties (Optional[Dict[str, Any]]) – Additional properties to track.
customer_data (Optional[CustomerData]) – Additional customer properties. These will be used if the customer’s properties are not already set.
- Returns:
The response from the API.
- Return type:
API Features¶
Customers¶
- class autumn.customers.Customers(http)[source]¶
An interface to Autumn’s customer API.
Warning
This class is not intended for public use. It is used internally by the
autumn.Clientclass. Do not initialize this class directly.- create(id, *, email=None, name=None, stripe_id=None, metadata=None)[source]¶
Create a new customer.
This function returns an awaitable coroutine when using the
AsyncClientclass.- Parameters:
id (str) – The ID of the customer to create.
email (Optional[str]) – The customer’s email address.
name (Optional[str]) – The customer’s name.
stripe_id (Optional[str]) – The customer’s Stripe ID. This can be a new or existing ID.
metadata (Optional[Dict[str, Any]]) – Additional metadata to attach to the customer.
- Returns:
The created customer.
- Return type:
- get(customer_id, expand=None)[source]¶
Get a customer by their ID.
This function returns an awaitable coroutine when using the
AsyncClientclass.
- get_billing_portal(customer_id, *, return_url=None)[source]¶
Get a billing portal URL for a customer.
This function returns an awaitable coroutine when using the
AsyncClientclass.
- list(*, limit=10, offset=0)[source]¶
- Return type:
Union[ListCustomerResponse,Coroutine[Any,Any,ListCustomerResponse]]
- pricing_table(customer_id)[source]¶
Get a pricing table for a customer.
This function returns an awaitable coroutine when using the
AsyncClientclass.- Parameters:
customer_id (str) – The ID of the customer to get a pricing table for.
- Returns:
The pricing table.
- Return type:
- update(customer_id, *, name=None, email=None, fingerprint=None)[source]¶
Update a customer.
This function returns an awaitable coroutine when using the
AsyncClientclass.
Features¶
- class autumn.features.Features(http)[source]¶
An interface to Autumn’s feature API.
Warning
This class is not intended for public use. It is used internally by the
autumn.Clientclass. Do not initialize this class directly.- set_balances(customer_id, balances)[source]¶
Set the balances of a customer.
This function returns an awaitable coroutine when using the
AsyncClientclass.
- set_usage(customer_id, feature_id, value)[source]¶
Set the usage of a feature for a customer.
This function returns an awaitable coroutine when using the
AsyncClientclass.
Products¶
- class autumn.products.Products(http)[source]¶
An interface to Autumn’s product API.
Warning
This class is not intended for public use. It is used internally by the
autumn.Clientclass. Do not initialize this class directly.Example:
import autumn client = autumn.Client(token="your_api_key") product = client.products.create( id="chat_messages", name="Chat Messages", ) print(product.name) # Chat Messages
- create(id, *, name, is_add_on=False, is_default=False, items=None, free_trial=None)[source]¶
Create a new product.
This function returns an awaitable coroutine when using the
AsyncClientclass.- Parameters:
id (str) – The ID of the product.
name (str) – The name of the product.
is_add_on (bool) – Whether the product is an add-on.
is_default (bool) – Whether the product is a default product.
items (Optional[List[ProductItem]]) – The items of the product.
free_trial (Optional[FreeTrial]) – The free trial configuration of the product.
- Returns:
The response from the API.
- Return type:
- delete(id)[source]¶
Delete a product.
This function returns an awaitable coroutine when using the
AsyncClientclass.- Parameters:
id (str) – The ID of the product to delete.
- Returns:
This is a placeholder type. Treat it as
None.- Return type:
Empty
- get(id)[source]¶
Get a product by its ID.
This function returns an awaitable coroutine when using the
AsyncClientclass.- Parameters:
id (str) – The ID of the product to get.
- Returns:
The response from the API.
- Return type:
- get_referral_code(customer_id, program_id)[source]¶
Get a referral code for a customer.
This function returns an awaitable coroutine when using the
AsyncClientclass.- Parameters:
- Returns:
The response from the API.
- Return type:
- list(customer_id)[source]¶
List products for a customer.
This function returns an awaitable coroutine when using the
AsyncClientclass.- Parameters:
customer_id (str) – The ID of the customer to list products for.
- Returns:
The response from the API.
- Return type:
- redeem_referral_code(code, customer_id, reward_id)[source]¶
Redeem a referral code for a customer.
This function returns an awaitable coroutine when using the
AsyncClientclass.
- update(id, *, name, is_add_on=False, is_default=False, items=None, free_trial=None)[source]¶
Update a product.
This function returns an awaitable coroutine when using the
AsyncClientclass.- Parameters:
id (str) – The ID of the product to update.
name (str) – The new name of the product.
is_add_on (bool) – Whether the product is an add-on.
is_default (bool) – Whether the product is the default product.
items (Optional[List[ProductItem]]) – The new items of the product.
free_trial (Optional[FreeTrial]) – The new free trial of the product.
- Returns:
This is a placeholder type. Treat it as
None.- Return type:
Empty
Entities¶
- class autumn.entities.Entities(http)[source]¶
An interface to Autumn’s entities API.
Warning
This class is not intended for public use. It is used internally by the
autumn.Clientclass. Do not initialize this class directly.- create(customer_id, id, feature_id, name)[source]¶
Create an entity for a customer.
This function returns an awaitable coroutine when using the
AsyncClientclass.
- delete(customer_id, entity_id)[source]¶
Delete an entity for a customer.
This function returns an awaitable coroutine when using the
AsyncClientclass.
- get(customer_id, entity_id, expand=None)[source]¶
Get an entity by their ID.
This function returns an awaitable coroutine when using the
AsyncClientclass.
- transfer(customer_id, to_entity_id, product_id, from_entity_id=None)[source]¶
Transfer a product from one entity to another.
This function returns an awaitable coroutine when using the
AsyncClientclass.- Parameters:
customer_id (str) – The ID of the customer who owns the entities.
to_entity_id (str) – The ID of the entity to transfer the product to.
product_id (str) – The ID of the product to transfer.
from_entity_id (Optional[str]) – The ID of the entity to transfer the product from. If not provided, transfers from the customer’s general balance.
- Returns:
The result of the transfer operation.
- Return type:
TransferProductResult
Exceptions¶
- class autumn.error.AutumnValidationError(message, code)[source]¶
Exception raised when a validation error occurs. This is raised when the API returns a response that isn’t recognized by the library.