Skip to main content

Dow Jones DNA Streaming Project

Project description

How To Use

This a Python3 library is for Dow Jones customers consuming data from a Dow Jones Factiva Stream.

To use this we recommend ‘pip installing’ this by making the following addition to your requirements.txt:

git+https://git@github.com/dowjones/dj-dna-streams-python#egg=dj-dna-streams-python

Auth

There are general two ways to authenticate.

  • Your User Key

  • UserId, ClientId, and Password

Configuring

To run this code, you need to provide credentials from one of the authentication methods and your subscriptions. There are 3 ways to do this. You can either set environment variables or you can use a configuration file.

1. Set environment variables.

To set your service account credentials, set either:

  • An environment variable named ‘USER_KEY’.

  • Three environment variable named ‘USER_ID’, ‘CLIENT_ID’, and ‘PASSWORD’.

To set your subscription ID, simply set an environment variable named ‘SUBSCRIPTION_ID’ like so

export SUBSCRIPTION_ID="ABC1234567889"

The code above is the command line expression for setting this environment variable on Mac OSX. Other operating systems might have a slightly different techniques for setting environment variables on the command line.

2. Using the configuration file.

In this codebase you will find a file named ‘customer_config.json’. You are not required to use this file. If you prefer to use this configuration file, follow these directions: Open this file and add your service account credentials. Then add your subscription IDs. Remember that this is a JSON file so follow basic JSON formatting and syntax conventions.

3. Pass in variables as function arguments.

You may pass your service account credentials (user_id, client_id, and password) to the Listener constructor like so:

from dnaStreaming.listener import Listener
# User key authentication
listener = Listener(user_key=<YOUR USER KEY>)

# UserId, ClientId and Password authentication
listener = Listener(user_id=<YOUR USER ID>, client_id=<YOUR_CLIENT_ID>, password=<YOUR_PASSWORD>)

Or you may use the environment variables. Remember that passing credentials and subscription ID(s) in this way will override the environment variable and the config file settings.

from dnaStreaming.listener import Listener

listener = Listener()

4. Listening to messages

You may want to listen messages synchronously like so:

def callback(message, subscription_id):
    print('Subscription ID: {}: Message: {}'.format(subscription_id, message.data.__str__()))
    return True  # If desired return False to stop the message flow. This will unblock the process as well.

listener.listen(callback, maximum_messages=10)  # Omitting maximum_messages means you will continue to get messages as they appear. Can be a firehose. Use with caution.
# You may pass subscription ID as a parameter to the listen function

You may want to listen messages asynchronously like so:

def callback(message, subscription_id):
    print('Subscription ID: {}: Message: {}'.format(subscription_id, message.data.__str__()))

future = listener.listen_async(callback)
# After calling `listed_async` you need to keep the main thread alive.

for count in range(0, 5):
    sleep(1)

# Stop receiving messages after 5 seconds
if future.running():
    future.cancel()

Log Files

Very minimal logging is written to the module’s path ‘logs/dj-dna-streaming-python.log’. To keep maintenance simple this log is overwritten every time the app starts.

Testing

cd dnaStreaming/test
pip install -r requirements.txt
py.test . -s

or, alternatively, to test against python2.7 and python3.5:

tox

Flake8

If you are maintaining this library, ensure you run flake8 before you commit. At project root command line:

flake8 ./dnaStreaming ./tests

Running the Demonstration Code/Development

If you are enhancing this codebase (and not just using it as a library), follow these example MacOS steps:

1. Checkout the Project from Git.

2. Go to the Project Root.

3. Create a Virtual Environment.

virtualenv venv

4. Then activate the virutal environment by executing this command:

source ./venv/bin/activate

5. Install the Dependencies

pip install -r requirements.txt

6. Install the App:

python setup.py install

7. Set the Configuration Variables

See the config section.

8. Run the Demo Code

Running Non-Docker Demo:

Execute the following at the project root:

python ./dnaStreaming/demo/show_stream.py -s

Or

python ./dnaStreaming/demo/show_stream_async.py -s

If you are having ImportError: No module named … run this in your terminal before running the demo:

export PYTHONPATH='.'

Running Docker Demo

Execute the following at the project root:

docker build -f ./DockerfileDemo -t dj-dna-streaming-python .

docker run -it \
-e USER_ID=<your user ID> \
-e CLIENT_ID=<your client ID> \
-e PASSWORD=<your password> \
-e SUBSCRIPTION_ID=<your subscription ID> \
dj-dna-streaming-python

or:

docker run -it \
-e USER_KEY=<your user KEY> \
-e SUBSCRIPTION_ID=<your subscription ID> \
dj-dna-streaming-python

Project details


Download files

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

Source Distribution

dnaStreaming-2.0.2.tar.gz (13.2 kB view details)

Uploaded Source

Built Distributions

dnaStreaming-2.0.2-py3.9.egg (28.9 kB view details)

Uploaded Egg

dnaStreaming-2.0.2-py3-none-any.whl (16.0 kB view details)

Uploaded Python 3

File details

Details for the file dnaStreaming-2.0.2.tar.gz.

File metadata

  • Download URL: dnaStreaming-2.0.2.tar.gz
  • Upload date:
  • Size: 13.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.6.1 requests/2.24.0 setuptools/50.3.2 requests-toolbelt/0.9.1 tqdm/4.51.0 CPython/3.9.0

File hashes

Hashes for dnaStreaming-2.0.2.tar.gz
Algorithm Hash digest
SHA256 864c938a5aeadd20c81550479cd22c20f26c1bf62dd733a04acff67c485e0f0f
MD5 38a476f19d45fd391df48b8ff34adeec
BLAKE2b-256 483fdc3deaac567313af2ebbbaa17a84de7b40a347e3f8b6058daddec4f6f460

See more details on using hashes here.

File details

Details for the file dnaStreaming-2.0.2-py3.9.egg.

File metadata

  • Download URL: dnaStreaming-2.0.2-py3.9.egg
  • Upload date:
  • Size: 28.9 kB
  • Tags: Egg
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.9.15

File hashes

Hashes for dnaStreaming-2.0.2-py3.9.egg
Algorithm Hash digest
SHA256 62759c33a9937119058e06adecefb3e0250110ad5c3c223c8a0831bd1d1a64c8
MD5 4ba272244a02c743f040967a56a227b7
BLAKE2b-256 5009920d6aefff855445feed205ab315ee69b63e69c6392df601ad42c29ed39f

See more details on using hashes here.

File details

Details for the file dnaStreaming-2.0.2-py3-none-any.whl.

File metadata

  • Download URL: dnaStreaming-2.0.2-py3-none-any.whl
  • Upload date:
  • Size: 16.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.6.1 requests/2.24.0 setuptools/50.3.2 requests-toolbelt/0.9.1 tqdm/4.51.0 CPython/3.9.0

File hashes

Hashes for dnaStreaming-2.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 2914c828f0556219d35d5c7c8449ef767dd3bd0d52cd99fdc82c18b2fe95127f
MD5 27c4e15b7dd4cc97fee3776e591d7fa7
BLAKE2b-256 86edc261d6a972dbae5710b5162330544578f02882f46ea283cbee5df3152b57

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page