Skip to main content

PulseRoute SDK — predictive payment routing with automatic failover

Project description

PulseRoute Python SDK

Zero-dependency Python client for PulseRoute predictive payment routing. Uses only the standard library.

Installation

pip install pulseroute

Quick Start

import os
from pulseroute import PulseRouteClient, RouteRequest, OutcomeRequest

client = PulseRouteClient(
    api_key=os.environ["PULSEROUTE_KEY"],
    base_url="https://api.pulseroute.dev",
)

# Pre-transaction: get routing decision
route = client.get_route(RouteRequest(country="US", currency="USD", card_type="visa"))

# Process payment with route.processor_id...

# Post-transaction: report outcome (fire-and-forget)
client.report_outcome(OutcomeRequest(
    rule_id=route.rule_id,
    processor_id=route.processor_id,
    success=True,
    latency_ms=145.0,
))

# On shutdown
client.shutdown()

Stripe + Adyen Example

import time

def process_payment(country, currency, card_type, amount_cents):
    route = client.get_route(RouteRequest(country=country, currency=currency, card_type=card_type))
    start = time.time()

    try:
        if route.processor_id == "stripe":
            result = stripe.Charge.create(amount=amount_cents, currency=currency)
        else:
            result = adyen.payments.create(amount=amount_cents, currency=currency)

        latency = (time.time() - start) * 1000
        client.report_outcome(OutcomeRequest(
            rule_id=route.rule_id,
            processor_id=route.processor_id,
            success=True,
            latency_ms=latency,
        ))
        return result

    except PaymentError as e:
        latency = (time.time() - start) * 1000
        client.report_outcome(OutcomeRequest(
            rule_id=route.rule_id,
            processor_id=route.processor_id,
            success=False,
            latency_ms=latency,
            error_code=e.code,
        ))
        raise

Context Manager

with PulseRouteClient(api_key="your-key") as client:
    route = client.get_route(RouteRequest(country="US", currency="USD"))
    # ... process payment ...
# Auto-flushes and shuts down on exit

Configuration

Option Default Description
api_key None API key for authentication
base_url http://localhost:8080 PulseRoute API URL
timeout 5.0 HTTP request timeout (seconds)
flush_interval 5.0 Outcome flush interval (seconds)
batch_size 50 Max outcomes per flush

Features

  • Zero dependencies — uses only Python standard library (urllib, json, threading)
  • Local decision cache — falls back to cached decision if API unreachable
  • Fire-and-forget outcomes — buffered and flushed async in batches
  • Thread-safe — daemon flush thread, lock-protected buffer
  • Context manager — works with with statements

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

pulseroute-0.1.0.tar.gz (5.0 kB view details)

Uploaded Source

Built Distribution

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

pulseroute-0.1.0-py3-none-any.whl (5.9 kB view details)

Uploaded Python 3

File details

Details for the file pulseroute-0.1.0.tar.gz.

File metadata

  • Download URL: pulseroute-0.1.0.tar.gz
  • Upload date:
  • Size: 5.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.13

File hashes

Hashes for pulseroute-0.1.0.tar.gz
Algorithm Hash digest
SHA256 b08222a3f30d8e114b3bdea8346650fc58cc63590c03d96eced0c1d9063f9a56
MD5 f46de35046adb57713156b3c0e7eb4d3
BLAKE2b-256 15acf9a0c101965d2e8d0e08357434bb28f83d58f825e01b684cec3a1ddef161

See more details on using hashes here.

File details

Details for the file pulseroute-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: pulseroute-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 5.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.13

File hashes

Hashes for pulseroute-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 42c03f15eaf64e4b130e864d0a3700b98b56395c28145e80adf80dcd4b16671d
MD5 ea027de7b3d4ba1aa99469098d55dd83
BLAKE2b-256 e66462a7ec32163757c0fc84c433d0783431d5029eb05828a709731a92a400ce

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