th2_common
Project description
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)
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:
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
File details
Details for the file th2_common-2.2.6.tar.gz
.
File metadata
- Download URL: th2_common-2.2.6.tar.gz
- Upload date:
- Size: 17.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.2.0 pkginfo/1.6.1 requests/2.25.0 setuptools/50.3.2 requests-toolbelt/0.9.1 tqdm/4.54.0 CPython/3.8.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6da2ceb3440597bc0f24e3c5bbdf1217f25409dcf5b22713ba870f8dc50ddc3c |
|
MD5 | ee135181288a266e2c0b9dd5880ab5a8 |
|
BLAKE2b-256 | 7ada3d28049a754952e60707f2b815ded2a924520cc8e89b0d673cbc4c07f9dd |