Skip to main content

A lightweight Python client for PaymentsOS Management and Reporting APIs.

Project description

paymentsoslib

Package Description

A lightweight Python client for PaymentsOS Management and Reporting APIs.

This library wraps:

  • Session creation (Management API)
  • Report Request creation/retrieval (Reporting API)
  • Downloading and decompressing gzip CSV report files

This client performs real HTTP calls to PaymentsOS. Provide valid credentials and account details. Avoid logging sensitive data.

Usage

# 0. Initialize PaymentsOS client
client = PaymentsOS(
    email="account.email@company.com",
    password="PASSWORD",
    account_id="ACCOUNT_ID",
    environment="live",
    api_version="1.1.0",
    timeout=30
)

# Example: Using date between 6 months ago and yesterday
from dateutil.relativedelta import relativedelta

date_from = datetime.now() - relativedelta(months=6)
date_from = date_from.replace(hour=0, minute=0, second=0, microsecond=0)

date_to = datetime.now() - relativedelta(days=1)
date_to = date_to.replace(hour=0, minute=0, second=0, microsecond=0)

# 1. Create report request
result = client.create_report_request(
    report_template_id="REPORT_TEMPLATE_ID",
    date_from = date_from,
    date_to = date_to,
    report_name="MY_REPORT_NAME",
    filter_timezone="America/Bogota",
    display_timezone="America/Bogota",
    timezone="-05:00",
    include_sftp_report_name_prefix=True
)

print("Report ID request created:", result["id"])

report_request_id = result["id"]

# Poll while status is 'in_progress'
poll_seconds = 30            # choose your interval
timeout_seconds = 600        # e.g., 10 minutes overall timeout
deadline = time.time() + timeout_seconds

while True:
    # 2. Retrieve current status
    response = client.retrieve_report_request(report_request_id=report_request_id)
    response.raise_for_status()

    status_body = response.json()
    status = (status_body.get("status") or "").strip()
    print(f"[{time.strftime('%Y-%m-%d %H:%M:%S')}] Report {report_request_id} status: {status}")

    if status != "in_progress":
        if status == "completed_successfully":
            print("Report completed successfully.")

            report_body = response.json()
            report_url = report_body.get("report_url")
            print(report_url)

            # 3. Download report
            output_path = r"C:\Admin\Output\File.csv"
            client.download_report_to_csv(report_url=report_url, output_path=output_path)
        elif status in {"Failed", "Error"}:
            print("Report failed. Decide whether to retry or alert.")
        else:
            print(f"Report finished with status '{status}'. Handle as needed.")
        break

    # Still in progress — check for timeout and sleep
    if time.time() >= deadline:
        raise TimeoutError(
            f"Report request '{report_request_id}' still 'in_progress' after {timeout_seconds}s."
        )

    time.sleep(poll_seconds)

Installation

Install python and pip if you have not already.

Then run:

pip install pip --upgrade

For production:

pip install paymentsoslib

This will install the package and all of it's python dependencies.

If you want to install the project for development:

git clone https://github.com/aghuttun/paymentsoslib.git
cd paymentsoslib
pip install -e ".[dev]"

Docstring

The script's docstrings follow the numpydoc style.

License

BSD License (see license file)

top

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

paymentsoslib-0.0.1.tar.gz (8.4 kB view details)

Uploaded Source

Built Distribution

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

paymentsoslib-0.0.1-py3-none-any.whl (8.2 kB view details)

Uploaded Python 3

File details

Details for the file paymentsoslib-0.0.1.tar.gz.

File metadata

  • Download URL: paymentsoslib-0.0.1.tar.gz
  • Upload date:
  • Size: 8.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for paymentsoslib-0.0.1.tar.gz
Algorithm Hash digest
SHA256 7451d64ea3eb76d7a4c21c0b9d80fc4495d23a396052bafa3418511c98f33587
MD5 dc9a279c6e2e0e0fb2c37acafcfbd726
BLAKE2b-256 79359de7163c824199f1a542e8f5b9e9458e73e2ee9c95e430572a67c72434fc

See more details on using hashes here.

File details

Details for the file paymentsoslib-0.0.1-py3-none-any.whl.

File metadata

  • Download URL: paymentsoslib-0.0.1-py3-none-any.whl
  • Upload date:
  • Size: 8.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for paymentsoslib-0.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 12fd265788cb2658822e2f342a8be139d1fc4eab2cf12f7744fbc4c23588fceb
MD5 48544df2c4541e1da27b11c6891ce562
BLAKE2b-256 188b0798d7e553acd8d2fd21b91dfbf6934faea74322efd0c4d14f2ce023f22c

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