Coder Social home page Coder Social logo

testvidya11 / keenclient-python Goto Github PK

View Code? Open in Web Editor NEW

This project forked from keenlabs/keenclient-python

0.0 1.0 0.0 152 KB

Official Python client for the Keen IO API. Build analytics features directly into your Python apps.

Home Page: https://keen.io/docs

License: MIT License

Python 100.00%

keenclient-python's Introduction

Keen IO Official Python Client Library

Build Status

This is the official Python Client for the Keen IO API. The Keen IO API lets developers build analytics features directly into their apps.

This is still under active development. Stay tuned for improvements!

Installation

Use pip to install!

pip install keen

This client is known to work on Python 2.6, 2.7, 3.2, and 3.3

Usage

To use this client with the Keen IO API, you have to configure your Keen IO Project ID and its access keys (if you need an account, sign up here - it's free).

Setting a write key is required for publishing events. Setting a read key is required for running queries. The recommended way to set this configuration information is via the environment. The keys you can set are KEEN_PROJECT_ID, KEEN_WRITE_KEY, and KEEN_READ_KEY.

If you don't want to use environment variables for some reason, you can directly set values as follows:

keen.project_id = "xxxx"
keen.write_key = "yyyy"
keen.read_key = "zzzz"

You can also configure unique client instances as follows:

client = KeenClient(
    project_id="xxxx",
    write_key="yyyy",
    read_key="zzzz"
)
Send Events to Keen IO

Once you've set KEEN_PROJECT_ID and KEEN_WRITE_KEY, sending events is simple:

keen.add_event("sign_ups", {
    "username": "lloyd",
    "referred_by": "harry"
})
Send Batch Events to Keen IO

You can upload Events in a batch, like so:

# uploads 4 events total - 2 to the "sign_ups" collection and 2 to the "purchases" collection
keen.add_events({
    "sign_ups": [
        { "username": "nameuser1" },
        { "username": "nameuser2" } 
    ],
    "purchases": [
        { "price": 5 },
        { "price": 6 }
    ]
})

That's it! After running your code, check your Keen IO Project to see the event/events has been added.

Do analysis with Keen IO

Here are some examples of querying. Let's assume you've added some events to the "purchases" collection.

keen.count("purchases") # => 100
keen.sum("purchases", target_property="price") # => 10000
keen.minimum("purchases", target_property="price") # => 20
keen.maximum("purchases", target_property="price") # => 100
keen.average("purchases", target_property="price") # => 49.2

keen.sum("purchases", target_property="price", group_by="item.id") # => [{ "item.id": 123, "result": 240 }, { ... }]

keen.count_unique("purchases", target_property="user.id") # => 3
keen.select_unique("purchases", target_property="user.email") # => ["[email protected]", "[email protected]"]

keen.extraction("purchases", timeframe="today") # => [{ "price" => 20, ... }, { ... }]

keen.multi_analysis("purchases", analyses={"total":{"analysis_type":"sum", "target_property":"price"}, "average":{"analysis_type":"average", "target_property":"price"}) # => {"total":10329.03, "average":933.93}

step1 = {
    "event_collection": "signup",
    "actor_property": "user.email"
}
step2 = {
    "event_collection": "purchase",
    "actor_property": "user.email"
}
keen.funnel([step1, step2], timeframe="today") # => [2039, 201]

Changelog

0.2.2
  • Added interval to multi_analysis.
0.2.1
  • Added stacktrace_id and unique_id to Keen API errors.
0.2.0
  • Added add_events method to keen/init.py so it can be used at a module level.
  • Added method to generate image beacon URLs.
0.1.9
  • Added support for publishing events in batches
  • Added support for configuring client automatically from environment
  • Added methods on keen module directly
0.1.8
  • Added querying support
0.1.7
  • Bugfix to use write key when sending events - do not use 0.1.6!
0.1.6
  • Changed project token -> project ID.
  • Added support for read and write scoped keys.
  • Added support for generating scoped keys yourself.
  • Added support for python 2.6, 3.2, and 3.3
0.1.5
  • Added documentation.

To Do

  • Bulk event insert
  • Asynchronous insert
  • Scoped keys

Questions & Support

If you have any questions, bugs, or suggestions, please report them via Github Issues. Or, come chat with us anytime at users.keen.io. We'd love to hear your feedback and ideas!

Contributing

This is an open source project and we love involvement from the community! Hit us up with pull requests and issues.

keenclient-python's People

Contributors

dkador avatar tmschl avatar spraetz avatar jgeewax avatar testvidya11 avatar

Watchers

 avatar

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.