A typed Authorize.Net client using httpx and pydantic.
Project description
python-authorizenet
A typed Authorize.net client using httpx and pydantic.
Features
- Supports both synchronous and asynchronous requests via httpx
- Schema is based on pydantic using the official XSD
- Supports the entire Authorize.net API
- Easily serialize requests and responses into JSON, XML and dicts
- Use as a context manager to leverage httpx's connection pooling
Requirements
- Python >= 3.9
Installation
pip install python-authorizenet
Usage
to instantiate the client:
import authorizenet
client = authorizenet.Client(
login_id="<your login id here>",
transaction_key="<your transaction key here>"
)
Then to make requests:
request = authorizenet.CreateCustomerProfileRequest(
profile=authorizenet.CustomerProfileType(
description="John Doe",
email="jdoe@mail.com",
merchant_customer_id="12345",
),
)
response = client.customer_profiles.create(request)
Or to make the request asynchronously:
import asyncio
import authorizenet
client = authorizenet.AsyncClient(
login_id="<your login id here>",
transaction_key="<your transaction key here>"
)
request = authorizenet.CreateCustomerProfileRequest(
profile=authorizenet.CustomerProfileType(
description="John Doe",
email="jdoe@mail.com",
merchant_customer_id="12345",
),
)
async def my_async_func():
return await client.customer_profiles.create(request)
response = asyncio.run(my_async_func())
Note: asyncio is optional here and is only used for demonstrative purposes.
The client can also be used as a context manager which makes use of httpx's connection pooling.
import authorizenet
with authorizenet.Client(
login_id="<your login id here>",
transaction_key="<your transaction key here>"
) as client:
request = authorizenet.CreateCustomerProfileRequest(
profile=authorizenet.CustomerProfileType(
description="John Doe",
email="jdoe@mail.com",
merchant_customer_id="12345",
),
)
response = client.customer_profiles.create(request)
Or if running async:
import authorizenet
async with authorizenet.AsyncClient(
login_id="<your login id here>",
transaction_key="<your transaction key here>"
) as client:
request = authorizenet.CreateCustomerProfileRequest(
profile=authorizenet.CustomerProfileType(
description="John Doe",
email="jdoe@mail.com",
merchant_customer_id="12345",
),
)
response = await client.customer_profiles.create(request)
All requests within the context manager will use the same connection pool, which is useful if you're making several requests at once and want to avoid connection creation overhead.
By default the client is in sandbox mode. To go live:
import authorizenet
client = authorizenet.AsyncClient(
login_id="<your login id here>",
transaction_key="<your transaction key here>",
sandbox=False
)
Testing
To run the tests:
poetry run pytest
There are a growing number of examples in the tests directory.
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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters