Giter VIP home page Giter VIP logo

analytics-agent-python's Introduction

Mashape Analytics Python Agent

for more information on Mashape Analytics, please visit apianalytics.com

Installation

pip install mashape-analytics

If you're using Mac OS X. You may need virtualenv. This is especially the case for El Capitan.

Usage

Django

Add the following middleware and setting in settings.py:

MIDDLEWARE_CLASSES = (
  'mashapeanalytics.middleware.DjangoMiddleware',
)

# Mashape Analytics
MASHAPE_ANALYTICS_SERVICE_TOKEN = 'SERVICE_TOKEN' # Replace with your App Service Token
MASHAPE_ANALYTICS_ENVIRONMENT = 'production' # Leave blank for default, or replace with your Environment ID

Note: See Django Configurations for a full list of configuration properties.

Flask

Add the middleware to wsgi_app:

from mashapeanalytics.middleware import FlaskMiddleware as MashapeAnalytics
from flask import Flask

app = Flask(__name__)
app.wsgi_app = MashapeAnalytics(app.wsgi_app, 'SERVICE_TOKEN', 'production') # Attach middleware with environment, `production`

@app.route('/')
def hello_world():
    return 'Hello World!'

if __name__ == '__main__':
    app.run()

Note: See WSGI Configurations for a full list of configuration properties.

Pyramid

This example starts from Pyramid's simplest application.

Wrap the middleware to app:

from mashapeanalytics.middleware import WsgiMiddleware as MashapeAnalytics
from wsgiref.simple_server import make_server
from pyramid.config import Configurator
from pyramid.response import Response


def hello_world(request):
  return Response('Hello %(name)s!' % request.matchdict)

if __name__ == '__main__':
  config = Configurator()
  config.add_route('hello', '/hello/{name}')
  config.add_view(hello_world, route_name='hello')
  app = config.make_wsgi_app()

  app = MashapeAnalytics(app, 'SERVICE_TOKEN', 'production') # Attach middleware with environment, `production`

  server = make_server('0.0.0.0', 8080, app)
  server.serve_forever()

Note: See WSGI Configurations for a full list of configuration properties.

Pylons

Add the middleware to your ini file.

[filter:mashape_analytics]
use = egg:mashape_analytics#mashape_analytics
serviceToken = SERVICE_TOKEN
environment = production

[pipeline]
pipeline = mashape_analytics my_application

Note: See WSGI Configurations for a full list of configuration properties.

Copyright and license

Copyright Mashape Inc, 2015.

Licensed under the MIT License

analytics-agent-python's People

Contributors

kennethklee avatar orliesaurus 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.