Skip to main content

A tiny package for cXense API

Project description

A Tiny package for cXense API

Make cXense API simple.


Python 3.6 above  (did't test in other versions)


pip install pyCx

How to use

Step 1: create a Cx object with env.yaml by using CxConfig

import os
from pyCx import Cx, CxConfig

# using env.yaml
fp = os.path.abspath('env.yaml')
cx = Cx(CxConfig(fp))

# or just passing dict value
my_cx_config = {
    'site_id': YOUR_ID,
    'username': 'YOUR_USERNAME',
    'secret': 'YOUR_KEY',
    'apiserver': '',
cx = Cx(my_cx_config)

and here's env.yaml sample:

  site_id: YOUR_ID
  username: YOUR_USERNAME
  secret: YOUR_KEY

Step 2: send a /traffic request by using CxQuery

import json
from pyCx import Cx, CxenseURL
from pyCx.helpers import date_range

cx = Cx(my_cx_config)

# get CxQuery object from Cx
query = cx.get_query()

# apply date range for what we want, here will get data from 11/01 to 11/30 (include).
dates = date_range('2018-11-01', '2018-12-01')

# remember do a reset() before a new request.
status, header, content = query.reset() \
    .uri(CxenseURL.TRAFFIC) \
    .add_filter({'type': 'and', 'filters': [{'group': "PREFIX-articleid", 'items': ['123405'], 'type': "keyword"}]}) \
    .add_fields(['events', 'uniqueUsers']) \
    .add_history_fields(['events', 'uniqueUsers']) \
    .add_dates(dates) \

# print results
result = json.loads(content.decode('utf-8'))





Lastest Version

0.0.11 (Lastest, 2018/12/13)

other releases



Project details

Download files

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

Files for pyCx, version 0.0.12
Filename, size File type Python version Upload date Hashes
Filename, size pyCx-0.0.12.tar.gz (7.4 kB) File type Source Python version None Upload date Hashes View

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring DigiCert DigiCert EV certificate Facebook / Instagram Facebook / Instagram PSF Sponsor Fastly Fastly CDN Google Google Object Storage and Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Salesforce Salesforce PSF Sponsor Sentry Sentry Error logging StatusPage StatusPage Status page