Client code for python Mona instrumentation
Project description
Python Client
Using Mona's wrapper for the "requests" package
instead of importing "requests", import the requests object from mona_requests:
from mona_requests import requests
After that, use requests as usual. The only difference in behavior is that any request or session will always have a header "mona_id" added to it, with the current context's complete id.
Concurrency
Mona saves the ARC's id on a special variable, which is local to the thread and to greenlets. This means that if you start a new thread/greenlet, by default the new thread will have an empty context.
This is usually the preffered behavior, as a new thread usually means a new received request (on servers) or a completely new run of an algorithm.
If by any chance you'd like to continue with the same context on a new thread, just use the child class MonaThread under mona_thread.py. This class takes care of transferring the full context id to the newly started thread.
Using Mona's GCP pubusb support
We provide support for transferring Mona context data via pubsub using our class MonaPublisherClient (child of PublisherClient). This class extends the functionaliy of the publish() method, by adding the current context id via the message attributes.
On the other side, if you subscribe to a pubsub topic and wish to have your mona context change according to the publisher's context, just send any message to our init_mona_from_pubsub_message(msg) method. That's it.
Testing the client code
The client's tests are written using the pytest framework, so in order to run the tests (assuming you have pytest installed on your environment), you just need to type "pytest" to your shell.
The only caveat is in pubsub_test.py, which you need to use a pubsub emulator to activate. Please refer to that file for explanations.
Uploading new version to PyPI
The main reference to follow to do that is on: https://packaging.python.org/tutorials/packaging-projects/
- Register on PyPI with your mona email: https://pypi.org/
- Ask itai@monalabs.io to add you as collaborator
- If not installed, install twine: $ python3 -m pip install --user --upgrade twine
- Change version number under setup.py
- If a new dependency is required, add it under setup.py under "install_requires"
- If not installed, install build tools: $ python3 -m pip install --user --upgrade setuptools wheel
- Build new version: $ python3 setup.py sdist bdist_wheel
- Upload new version (can change '*' to actual version): $ python -m twine upload dist/_
Configuration and Big Red Button
If you'd like to set up configuration for mona, you can fill a simple json configuration file. See mona_client_config.json for the default configuration file used. There is currently only one configuration option, which is the "Big Red Button" - the "disable_all" configuration, which, when set to true, completely disables all mona activity (no more exporting and context inits).
Mona listens to changes on the configuartion file under the environment variable "MONA_CLIENT_CONFIG_FILE". So if you want to disable mona while running, just change "disable_all" from "false" to "true" in your config file and mona will update automatically.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file mona_client-0.0.5.tar.gz
.
File metadata
- Download URL: mona_client-0.0.5.tar.gz
- Upload date:
- Size: 7.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.12.1 pkginfo/1.4.2 requests/2.20.1 setuptools/40.6.2 requests-toolbelt/0.8.0 tqdm/4.28.1 CPython/3.6.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | d41c866237107166d75cca0f4e31ad02331e4e656f8e8261dffe86d2cbb69c21 |
|
MD5 | 81b7db579e4a9130a4bd8e6518f4d7af |
|
BLAKE2b-256 | 22d32335a7924d3b350128000920790079805711afcf07dd1a9cf557446cbfb1 |
Provenance
File details
Details for the file mona_client-0.0.5-py3-none-any.whl
.
File metadata
- Download URL: mona_client-0.0.5-py3-none-any.whl
- Upload date:
- Size: 9.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.12.1 pkginfo/1.4.2 requests/2.20.1 setuptools/40.6.2 requests-toolbelt/0.8.0 tqdm/4.28.1 CPython/3.6.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | dae8e2a6a6a5201ddaf56f2f75f47bf230178fa7afd8bf653fb9aee9d8221a32 |
|
MD5 | 8aa24b84854d78ed953ee98b23517812 |
|
BLAKE2b-256 | ac337fde6ce2b564911a421787e2c5b7d78d503b9df2269949d178906a34f11d |