Skip to main content

ETL module for RD Station API database-optimized DataFrame processing

Project description

RD Station API Helper

A Python library for interacting with the RD Station API, providing ORM models, authentication, segmentation, contact, and event retrieval, as well as batch and parallel data fetching utilities.

PyPI version Last Commit Issues License

Features

  • RD Station API v2 support: Query segmentations, contacts, leads, and conversion events
  • ORM Models: SQLAlchemy models for RD Station entities (Segmentation, Contact, Lead, etc.)
  • Batch & Parallel Fetching: Utilities for efficient data extraction
  • Robust Error Handling: Comprehensive error handling and retry logic
  • Logging & Config Utilities: Easy configuration and logging
  • Type Hints: Full type hint support for better IDE experience

Installation

pip install rdstation-api-helper

Quick Start

1. Set up credentials

Create a secrets/rdstation_secret.json file with your RD Station API credentials:

{
  "RDSTATION_CLIENT_ID": "YOUR_CLIENT_ID",
  "RDSTATION_CLIENT_SECRET": "YOUR_CLIENT_SECRET",
  "RDSTATION_REFRESH_TOKEN": "YOUR_REFRESH_TOKEN"
}

2. Basic usage

from rdstation_api_helper import RDStationAPI

# Initialize API client (loads credentials from environment or .env)
client = RDStationAPI()

# Fetch all segmentations
segmentations = client.get_segmentations()

# Fetch contacts for each segmentation
contacts = client.get_segmentation_contacts("segmentations_id")

# Fetch contact data for a specific UUID
status_code, contact_data = client.get_contact_data("contact_uuid")

# Fetch conversion events for a contact
status_code, events = client.get_contact_events("some-contact_uuid")

ORM Models

The package provides SQLAlchemy ORM models for RD Station entities, which can be used for database integration.

  • Segmentation
  • SegmentationContact
  • Contact
  • ContactFunnelStatus
  • ConversionEvents
  • Lead

Examples

Check the examples/ directory for comprehensive usage examples:

  • basic_usage.py - Simple report extraction

Parallel & Batch Fetching

The library provides a parallel_decorator utility to easily parallelize API calls for batch data fetching. This is used in the following methods of RDStationAPI:

  • get_contact_data_parallel(uuids: list[str])
  • get_contact_events_parallel(uuids: list[str])
  • get_contact_funnel_status_parallel(uuids: list[str])

These methods accept a list of UUIDs and fetch the corresponding data in parallel, handling rate limits and transient errors automatically. The decorator coordinates retries for 429/5xx/network errors and ensures each result is tagged with its UUID.

Usage Example

from rdstation_api_helper import RDStationAPI

client = RDStationAPI()
uuids = ["uuid1", "uuid2", "uuid3"]

# Fetch contact data in parallel
_, contact_results = client.get_contact_data_parallel(uuids)

# Fetch contact events in parallel
_, events_results = client.get_contact_events_parallel(uuids)

# Fetch funnel status in parallel
_, funnel_results = client.get_contact_funnel_status_parallel(uuids)

print(contact_results)
print(events_results)
print(funnel_results)

Features:

  • Automatic parallelization with configurable worker count
  • Handles 429/5xx/network errors with coordinated retries
  • Appends the UUID to each result for traceability

See the rdstation_api_helper/utils.py source for details.

Requirements

  • Python 3.10-3.12
  • pandas >= 2.0.0
  • python-dotenv >= 1.0.0
  • requests >= 2.32.4
  • tqdm >= 4.65.0

License

This project is licensed under the GPL License. See LICENSE file for details.

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

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

rdstation_api_helper-1.1.1.tar.gz (27.6 kB view details)

Uploaded Source

Built Distribution

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

rdstation_api_helper-1.1.1-py3-none-any.whl (29.1 kB view details)

Uploaded Python 3

File details

Details for the file rdstation_api_helper-1.1.1.tar.gz.

File metadata

  • Download URL: rdstation_api_helper-1.1.1.tar.gz
  • Upload date:
  • Size: 27.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.1.4 CPython/3.12.3 Linux/5.15.167.4-microsoft-standard-WSL2

File hashes

Hashes for rdstation_api_helper-1.1.1.tar.gz
Algorithm Hash digest
SHA256 6b22df2a757b816e0e64aa0fffcee5d6be1142cb3fdfe98c699cb1492e1ac3df
MD5 0676ee907e6a23e22202918207cccb12
BLAKE2b-256 2a9197a3745332cfe5c6cfbd37ba23198e8bfb376facba72b303d75bc2256866

See more details on using hashes here.

File details

Details for the file rdstation_api_helper-1.1.1-py3-none-any.whl.

File metadata

  • Download URL: rdstation_api_helper-1.1.1-py3-none-any.whl
  • Upload date:
  • Size: 29.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.1.4 CPython/3.12.3 Linux/5.15.167.4-microsoft-standard-WSL2

File hashes

Hashes for rdstation_api_helper-1.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 915d39e81a3cb6432b3d03ea32c9009c010a30ebc97d9afb25f81003713e6aad
MD5 18a4b06e1669a79180af0f8fecceac00
BLAKE2b-256 2daabd5c73d03510f653b3e130aceb36be59d44caf4e245d5df727ed64671292

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