This release is a pre-release and may not be stable for production use.
th2 common library (Python)
Installation
pip install th2-common
This package can be found on PyPI.
Usage
First things first, you need to import CommonFactory class:
from th2_common.schema.factory.common_factory import CommonFactory
Then you create an instance of imported class, choosing one of the options:
- Create factory with configs from default path (
/var/th2/config/*):factory = CommonFactory() - Create factory with configs from specified directory path (
path/*):factory = CommonFactory(config_path=...) - Create factory with configs from specified file paths:
factory = CommonFactory(rabbit_mq_config_filepath=..., mq_router_config_filepath=..., grpc_router_config_filepath=..., cradle_config_filepath=..., custom_config_filepath=...) - Create factory with configs from command line arguments (
sys.argv):factory = CommonFactory.create_from_arguments() - Create factory with configs from specified arguments:
factory = CommonFactory.create_from_arguments(args) - Create factory with a namespace in Kubernetes and the name of the target th2 box from Kubernetes:
factory = CommonFactory.create_from_kubernetes(namespace, box_name)
Requirements for creatring factory with Kubernetes
-
It is necessary to have Kubernetes configuration written in ~/.kube/config. See more on kubectl configuration here.
-
It is necessary to have environment variables
CASSANDRA_PASSandRABBITMQ_PASSto use configs fromcradle.jsonandrabbitMQ.jsonas the passwords are not stored there explicitly. -
Also note that
generated_configsdirectory will be created to store.jsonfiles with configs from Kubernetes. Those files are overridden whenCommonFactory.create_from_kubernetes(namespace, box_name)is invoked again.
After that you can get various Routers through factory properties:
message_parsed_batch_router = factory.message_parsed_batch_router
message_raw_batch_router = factory.message_raw_batch_router
event_batch_router = factory.event_batch_router
message_parsed_batch_router is working with MessageBatch
message_raw_batch_router is working with RawMessageBatch
event_batch_router is working with EventBatch
See th2-grpc-common for details.
With router created, you can subscribe to pins (specifying callback function) or send data that router works with:
router.subscribe(callback) # subscribe to only one pin
router.subscribe_all(callback) # subscribe to one or several pins
router.send(message) # send to only one pin
router.send_all(message) # send to one or several pins
You can do these actions with extra pin attributes in addition to default ones.
router.subscribe(callback, attrs...) # subscribe to only one pin
router.subscribe_all(callback, attrs...) # subscribe to one or several pins
router.send(message, attrs...) # send to only one pin
router.send_all(message, attrs...) # send to one or several pins
Default attributes are:
message_parsed_batch_router- Subscribe:
subscribe,parsed - Send:
publish,parsed
- Subscribe:
message_raw_batch_router- Subscribe:
subscribe,raw - Send:
publish,raw
- Subscribe:
event_batch_router- Subscribe:
subscribe,event - Send:
publish,event
- Subscribe:
Metadata
Release files for th2-common 2.3.3.dev553905425
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| th2_common-2.3.3.dev553905425.tar.gz | 22.7 kB | Without provenance | Details for th2_common-2.3.3.dev553905425.tar.gz |
Release files / th2_common-2.3.3.dev553905425.tar.gz
| Download URL | th2_common-2.3.3.dev553905425.tar.gz |
|---|---|
| Size | 22.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
27b43b85ca12d55c3ac2b62a916d7de0a04dbb941b7d52525358e994f21e8882
|
|
BLAKE2b-256 checksum How to use checksums |
25d038ac94f083be103f8b5be96f68d319fb95193d2fa6f3745bd356932cb6d9
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/53.0.0 requests-toolbelt/0.9.1 tqdm/4.56.1 CPython/3.9.1
|
Security for th2-common 2.3.3.dev553905425
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.