Giter Club home page Giter Club logo

veristack-client-python's Introduction

Veristack Python Client

Client for interfacing to Veristack

Usage

from veristack import (
    Client, Event, DeviceDetails, PersonDetails, FileDetails, ACT_READ,
)

client = Client(
    client_id='8ee21be2-3284-48e7-ac07-c4dc33769014',
    client_secret='9ed2cd6a-14d5-432a-9518-b59043adde0a',
    uid='abcd',
    url='https://getfilehub.com/')
client.fetch_token()

client.get('https://getfilehub.com/api/accounts/')

event = Event(
    action_type=ACT_READ,
    device=DeviceDetails(),
    person=PersonDetails(username='foo', email='[email protected]',
                         fullname='Foo B. Bar'),
    files=[
        FileDetails.from_path('/path/to/file.txt'),
    ],
)

client.send_events([event])

If the server fails to process the event, an IOError is raised. If sending many messages at once (as shown above), it is hard to trace the error back to the individual event, also, only a portion of the events will have been sent. Further, this method opens and closes a connection for each batch being sent.

For a streaming interface (a persistent connection), you can use a slightly different method of writing events.

with client.get_event_writer() as writer:
    for e in events:
        writer.write(e)

This may be more suitable when dispatching events from a queue (so that they can be left in queue until accepted by the server.)

Generating test data

This package also provides an event generating tool named Genny. This tool will produce event streams for testing purposes. To use this tool, simply do:

VERIFY_SSL_CERTIFICATES=no python -m veristack --client-id=<id> --client-secret=<secret> --host=https://localhost/ --token-file=oauth.token

The above will disable SSL certificate checks, connect to the event receiver and send some events. The --token-file parameter saves the token to a file after it is obtained, reusing it on subsequent runs (instead of fetching a new token each time).

Testing

Install required dependencies:

pip install -r test.txt

Run tests and generate coverage report:

python -m pytest

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.