Skip to main content

Python wrapper for Helloasso APIV5

Project description

HelloAsso API Wrapper

versions license Pydantic v2

A fully typed Python wrapper for HelloAsso API. You will find information about HelloAsso on their website and their API swagger documentation.

The module is based on Pydantic for models validation and on HelloAsso's HaApiV5 for API calls.

Installation

pip install HelloAssoAPIWrapper

Usage

# Import the wrapper
from helloasso_api_wrapper import HelloAssoAPIWrapper

# Create an instance of `HelloAssoAPIWrapper`
hello_asso = HelloAssoAPIWrapper(
 api_base=settings.HELLOASSO_API_BASE,
 client_id=settings.HELLOASSO_CLIENT_ID,
 client_secret=settings.HELLOASSO_CLIENT_SECRET,
 timeout=60,
)

Usage example to init a checkout

from helloasso_api_wrapper import HelloAssoAPIWrapper
from helloasso_api_wrapper.exceptions import ApiV5BadRequest

from helloasso_api_wrapper.models.carts import (
 CheckoutPayer,
 InitCheckoutBody,
 InitCheckoutResponse,
)

# First create an instance of `HelloAssoAPIWrapper` with the previous snippet
hello_asso = HelloAssoAPIWrapper(
 api_base=settings.HELLOASSO_API_BASE,
 client_id=settings.HELLOASSO_CLIENT_ID,
 client_secret=settings.HELLOASSO_CLIENT_SECRET,
 timeout=60,
)

# Then use the wrapper to init a checkout
init_checkout_body = InitCheckoutBody(
 totalAmount=100, # The total amount of the checkout in cents
 initialAmount=100,
 itemName="Our first checkout",
 backUrl="https://yourwebsite.com/callback", # The url must use https
 errorUrl="https://yourwebsite.com/callback",,
 returnUrl="https://yourwebsite.com/callback",,
 containsDonation=False,
 payer=CheckoutPayer(
 firstName="Fabristpp",
 lastName="John",
 email="fabristpp@email.fr",
 ),
)

response: InitCheckoutResponse
try:
 response = self.hello_asso.checkout_intents_management.init_a_checkout(
 helloasso_slug,
 init_checkout_body,
 )
except ApiV5BadRequest as error:
 print("Failed to init a checkout")
 raise error

Structure of the module

Authentication is done on the background using HelloAsso's HaApiV5 module.

The module is organized around a class HelloAssoAPIWrapper containing all the methods to interact with the HelloAsso API.

This class expose multiple clients, allowing to interact with different parts of the API. All clients are located in the clients folder.

Pydantic models are located in the models folder. Models are usually really permissive, typing all fields as Nullable. This is because the API is not always clear about the fields that are required or not. Some assumptions are made to make the models more strict.

We expose exceptions from HaApiV5. You can import them directly: from helloasso_api_wrapper.exceptions import *

Documentation about HelloAsso API

You will find documentation about HelloAsso API endpoints on:

HelloAsso sandbox

HelloAsso provide a sandbox: api.helloasso-sandbox.com to test your integration.

Notification result webhooks

You should configure a webhook to receive the notification results. HelloAsso will make a POST request to the URL you provided with a JSON payload corresponding to a NotificationResultContent object.

Development

Models where first generated using HelloAsso swagger documentation, and then adapted to include additional models, use stricter types and add documentation. Some assumptions are made to make the models more strict.

Add new methods

Currently, most endpoints are not implemented. To add a new method, you simply need to create a new method in the corresponding client. The method should use the self.api.callAndSerialize method to make the API call.

Example for checkout_intents_management init_a_checkout method:

def init_a_checkout(
 self,
 organization_slug: str,
 init_checkout_body: InitCheckoutBody,
) -> InitCheckoutResponse:
 return self.api.callAndSerialize(
 f"/organizations/{organization_slug}/checkout-intents", # API endpoint
 InitCheckoutResponse, # Model to serialize the response
 body=init_checkout_body, # Body of the request
 method="POST", # Request method
 )

Models auto-generation

This was used to generate the first version of the models. It should not be necessary to do it again.

Download the swagger file from the HelloAsso API documentation. It uses an old swagger 2 version. You need to convert it to OpenAPI 3.0.0 version. You can use the online tool Swagger Editor.

Then you can use the datamodel-codegen tool to generate the models:

datamodel-codegen --input HelloAssoV5OpenAPI.json --output HelloAssoAPIWrapper

Make a release on Pypi

You need to edit HelloAssoAPIWrapper version in helloasso_api_wrapper/__about__.py. Then make a release on GitHub and add a tag. The tag should match v*.*.*.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

helloassoapiwrapper-1.0.0.tar.gz (12.8 kB view details)

Uploaded Source

Built Distribution

helloassoapiwrapper-1.0.0-py3-none-any.whl (25.1 kB view details)

Uploaded Python 3

File details

Details for the file helloassoapiwrapper-1.0.0.tar.gz.

File metadata

  • Download URL: helloassoapiwrapper-1.0.0.tar.gz
  • Upload date:
  • Size: 12.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/5.1.0 CPython/3.12.4

File hashes

Hashes for helloassoapiwrapper-1.0.0.tar.gz
Algorithm Hash digest
SHA256 1b245acf2ff8a65e0840a5b490d528c6c89b8adbe58bc1ca2d997bbef28ecced
MD5 41939bdd951a182c83f829c38c7c530c
BLAKE2b-256 9b85d1834127b4008a2355c028ce2f1ed2dbda52b8b96a31fe83f873e8d982f8

See more details on using hashes here.

File details

Details for the file helloassoapiwrapper-1.0.0-py3-none-any.whl.

File metadata

File hashes

Hashes for helloassoapiwrapper-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 dea98f7e891549817ea1ca1e6bc05687bf30814d02e437917fd96883df9becc9
MD5 066f22786065c0d6d39ae1480357d02d
BLAKE2b-256 6d2d4987e1a5f4bac301af1d5fda7a266fcb9c29cd4ecda59117da14d95e1306

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page