/ReactiveXComponent.py

Python API for XComponent

Primary LanguagePythonApache License 2.0Apache-2.0

Build Status

Reactive XComponent API for Python

Reactive XComponent is a Python client API that allows you to interact with microservices generated with XComponent software.

Development

Dependencies

  • Python 3
  • Pipenv

Building and testing from sources

Install pipenv (the officially recommended packaging tool for Python):

sudo pip3 install pipenv

Install dependencies:

pipenv install --dev

Run build script:

pipenv run ./build.sh ( or build.bat)

A reactivexcomponent-X.Y.Z.tar.gz pip package is build on the dist\reactivexcomponent folder.

Sample code

Create a file called test.py.

from reactivexcomponent.xcomponent_api import XcomponentAPI

def callback(error, session):
    if error is not None:
        print('Error connecting to WebSocket bridge')
	print(error)
    if session is not None:
	publisher = session.create_publisher()
	publisher.send_message('COMPONENT NAME', 'STATEMACHINE NAME', 'MESSAGE TYPE', { 'JSON': 'MESSAGE' })

xc_api_file = "PATH TO A XCAPI FILE GENERATED BY XCStudio"
server_url = "wss://WEB_SOCKET_BRIDGE_SERVER:443"
api = XcomponentAPI()
api.create_session(xc_api_file, server_url, callback)

Run the Web socket bridge from a XComponent project and then run the test file as python test.py.

Running unit tests

Use the nose runner to run unit tests.

pipenv shell
cd reactivexcomponent
nosetests3 tests/unit reactivexcomponent --exe

Contributing

  1. Fork it!
  2. Create your feature branch: git checkout -b my-new-feature
  3. Commit your changes: git commit -am 'Add some feature'
  4. Push to the branch: git push origin my-new-feature
  5. Submit a pull request

License

Apache License V2