An XO core utils project.
Project description
# xoc-utils-python
An XO core project in python that provides utils functionalities, including data processing and Kafka client.
----
## Kafka
### Producer
```
producer = KProducer('kafka_server_origin', 'service_name')
message = json.dumps({
'hello': 'world'
})
producer.produce('topic_name', message)
```
Example [here](examples/kafka_producer.py)
### Consumer
Consumer without retry
```
consumer = KConsumer('kafka_server_origin', 'group_id', 'service_name', poll_timeout=1, retries=0)
# Add handler for a topic
def printMsg(msg):
print('consuming message: ', msg)
raise Exception('I am Exception.')
consumer.add_handler('topic_name', printMsg)
consumer.consume()
```
Example [here](examples/kafka_consumer.py).
If you want to use retry feature, you can just set retries to the times you want it to retry, like 3.
Example [here](examples/kafka_consumer_retry.py)
## Others
### Singleton
This provide you a way to create a singleton instance.
```
from xoc_utils import Singleton
class YourClass(metaclass=Singleton):
pass
```
## Development
You get start from [here](https://packaging.python.org/tutorials/distributing-packages/#packages).
To debug your package, you don't have to release it, you can just run
```
python setup.py install
```
then it will be installed on your machine.
An XO core project in python that provides utils functionalities, including data processing and Kafka client.
----
## Kafka
### Producer
```
producer = KProducer('kafka_server_origin', 'service_name')
message = json.dumps({
'hello': 'world'
})
producer.produce('topic_name', message)
```
Example [here](examples/kafka_producer.py)
### Consumer
Consumer without retry
```
consumer = KConsumer('kafka_server_origin', 'group_id', 'service_name', poll_timeout=1, retries=0)
# Add handler for a topic
def printMsg(msg):
print('consuming message: ', msg)
raise Exception('I am Exception.')
consumer.add_handler('topic_name', printMsg)
consumer.consume()
```
Example [here](examples/kafka_consumer.py).
If you want to use retry feature, you can just set retries to the times you want it to retry, like 3.
Example [here](examples/kafka_consumer_retry.py)
## Others
### Singleton
This provide you a way to create a singleton instance.
```
from xoc_utils import Singleton
class YourClass(metaclass=Singleton):
pass
```
## Development
You get start from [here](https://packaging.python.org/tutorials/distributing-packages/#packages).
To debug your package, you don't have to release it, you can just run
```
python setup.py install
```
then it will be installed on your machine.
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
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file xoc-utils-python-0.0.2.tar.gz.
File metadata
- Download URL: xoc-utils-python-0.0.2.tar.gz
- Upload date:
- Size: 5.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4def9ca2c5a5961a3bf26b723832bda9d5f988bafe6697d8b77a91a8339c1381
|
|
| MD5 |
ff3720c1f9e09cc361e1a426add11ec4
|
|
| BLAKE2b-256 |
35672ebddadc87e147ba3ea488923a8b8f7825776027c0e98ac224038213e561
|
File details
Details for the file xoc_utils_python-0.0.2-py3.6.egg.
File metadata
- Download URL: xoc_utils_python-0.0.2-py3.6.egg
- Upload date:
- Size: 9.7 kB
- Tags: Egg
- Uploaded using Trusted Publishing? No
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
aea74f3cefb5cc209b7930762073f96c9de93c2626fafa91f05203059b80940c
|
|
| MD5 |
39a310171a7b5a1bbae2e7b8154404de
|
|
| BLAKE2b-256 |
3a8969217f71e6f1698f7cd923a3e8e17d257981ed51b0af5a9c8921177d71cd
|