Code Monkey home page Code Monkey logo

rtbhouse-python-sdk's Introduction

RTB House SDK

Overview

This library provides an easy-to-use Python interface to RTB House API. It allows you to read and manage you campaigns settings, browse offers, download statistics etc.

API docs: https://api.panel.rtbhouse.com/api/docs

Installation

RTB House SDK can be installed with pip:

$ pip install rtbhouse_sdk

Usage example

Let's write a script which fetches campaign stats (imps, clicks, postclicks) and shows the result as a table (using tabulate library).

First, create config.py file with your credentials:

USERNAME = 'jdoe'
PASSWORD = 'abcd1234'

Set up virtualenv and install requirements:

$ pip install rtbhouse_sdk tabulate
from datetime import date, timedelta
from operator import attrgetter

from rtbhouse_sdk.client import BasicAuth, Client
from rtbhouse_sdk.schema import CountConvention, StatsGroupBy, StatsMetric
from tabulate import tabulate

from config import PASSWORD, USERNAME

if __name__ == "__main__":
    with Client(auth=BasicAuth(USERNAME, PASSWORD)) as api:
        advertisers = api.get_advertisers()
        day_to = date.today()
        day_from = day_to - timedelta(days=30)
        group_by = [StatsGroupBy.DAY]
        metrics = [
            StatsMetric.IMPS_COUNT,
            StatsMetric.CLICKS_COUNT,
            StatsMetric.CAMPAIGN_COST,
            StatsMetric.CONVERSIONS_COUNT,
            StatsMetric.CTR
        ]
        stats = api.get_rtb_stats(
            advertisers[0].hash,
            day_from,
            day_to,
            group_by,
            metrics,
            count_convention=CountConvention.ATTRIBUTED_POST_CLICK,
        )
    columns = group_by + metrics
    data_frame = [
        [getattr(row, c.name.lower()) for c in columns]
        for row in reversed(sorted(stats, key=attrgetter("day")))
    ]
    print(tabulate(data_frame, headers=columns))

License

MIT

rtbhouse-python-sdk's People

Contributors

abahdanovich avatar antoni-szych-rtbhouse avatar b-stankiewicz avatar badfunkydog avatar dszady-rtb avatar eujot avatar fburgiel avatar fiedosiukr avatar hzeg avatar jacek-jablonski avatar jkbak avatar kamilglod avatar kmasuhr avatar marcin-sokol-rtb avatar peku33 avatar renovate[bot] avatar slawomir-kubiak avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

rtbhouse-python-sdk's Issues

Action Required: Fix Renovate Configuration

There is an error with this repository's Renovate configuration that needs to be fixed. As a precaution, Renovate will stop PRs until it is resolved.

Error type: Cannot find preset's package (local>rtbhouse-apps/renovate-config)

Validation Error in RTBHouse Python SDK: impsCount Should Be Integer

We encountered a validation error when using the RTBHouse Python SDK to fetch RTB stats.
The error log indicates that the impsCount field received a float value instead of an integer, causing a validation failure in the Pydantic model.

api = Client(auth=BasicAuth(username, password))
stats = api.get_rtb_stats(advertiser.hash, start_date_, end_date_, group_by, metrics, count_convention=CountConvention.ATTRIBUTED_POST_CLICK)

requirements.txt
rtbhouse-sdk==11.1.0
pydantic==2.5.2
pydantic_core==2.14.5

Possible source of error:
imps_count: Optional[int] = None

Dependency Dashboard

This issue lists Renovate updates and detected dependencies. Read the Dependency Dashboard docs to learn more.

Awaiting Schedule

These updates are awaiting their schedule. Click on a checkbox to get an update now.

  • chore(deps): [PYTHON] Lock file maintenance

Open

These updates have all been created already. Click a checkbox below to force a retry/rebase of any.

Detected dependencies

docker-compose
docker-compose.yaml
dockerfile
Dockerfile
  • python 3.11.6-slim-buster
github-actions
.github/workflows/ci.yaml
  • actions/checkout v4
  • actions/setup-python v5
  • actions/cache v4
  • actions/checkout v4
  • actions/setup-python v5
  • softprops/action-gh-release v1
  • ubuntu 22.04
pep621
pyproject.toml
poetry
pyproject.toml
  • python >=3.8.1, <4.0
  • httpx ^0.27.0
  • pydantic >=1.9, <3.0
  • pydantic ^2.0.0
  • black ^24.0.0
  • flake8 ^7.0.0
  • isort ^5.10.1
  • mypy ^1.0
  • pylint ^3.0.0
  • pytest ^8.0.0
  • pytest-asyncio ^0.24.0
  • pytest-cov ^5.0.0
  • respx ^0.21.0

  • Check this box to trigger a request for Renovate to run again on this repository

group by lacks userSegments

Hi,
we are running into an error when using the new API version

api.get_rtb_stats(advertisers[0]['hash'], day_from, day_to, ['day','subcampaign','userSegments'], include_dpa=True)

We can use the filter "user_segments=",
but we cannot retrieve userSegments as a column in the answerset (as we did before).

In your documentation we have seen that you changed campaign to subcampaign.
Did you rename here, too?

regards,
Lars

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.