Skip to main content

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


Download files

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

Source Distribution

python_authorizenet-0.2.0.tar.gz (31.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

python_authorizenet-0.2.0-py3-none-any.whl (35.2 kB view details)

Uploaded Python 3

File details

Details for the file python_authorizenet-0.2.0.tar.gz.

File metadata

  • Download URL: python_authorizenet-0.2.0.tar.gz
  • Upload date:
  • Size: 31.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.3 CPython/3.12.6 Darwin/23.6.0

File hashes

Hashes for python_authorizenet-0.2.0.tar.gz
Algorithm Hash digest
SHA256 3841fa42bafd27c44acf0f99a4c35058439e885bb5371fc14faa75de278f403e
MD5 929c75f170cdb247f821195114163861
BLAKE2b-256 4332d6769285240f392614ff608b64aed2f1b8c29c25a625e0a6e4229a38cdc0

See more details on using hashes here.

File details

Details for the file python_authorizenet-0.2.0-py3-none-any.whl.

File metadata

File hashes

Hashes for python_authorizenet-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 630623c49ec6e867728fc0a5ca3c9ac12b63ff98a0237ec28abb029da2b94655
MD5 b683ea157f1fc7f4923c9f346bcf7029
BLAKE2b-256 2615346c00d1ab40cb3f419023a8a1c9d6bdb9895281446d74d29d30ee06fbd1

See more details on using hashes here.

Supported by

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