Metadata-Version: 2.4
Name: enos_dms
Version: 0.0.2
Summary: Data subscription with DMS package
Author-email: Xibin <songxibin@gmail.com>
License-Expression: MIT
Classifier: Programming Language :: Python :: 3
Classifier: Operating System :: OS Independent
Requires-Python: >=3.9
Description-Content-Type: text/markdown

# EnOS Subscription Python Client (`enos_dms`)

This is a Python implementation of the EnOS Subscription Client, designed to consume data from the EnOS Subscription Service. It handles authentication, message pulling, and automatic offset management.

## Features

- **Protocol Buffers**: Uses Google Protocol Buffers for efficient message serialization.
- **TCP Connection**: Maintains a persistent TCP connection to the EnOS Subscription Server.
- **Automatic Authentication**: Handles signature calculation and authentication flow.
- **SSL/TLS Support**: Supports encrypted connections using client and server certificates.
- **Auto-Commit**: Periodically commits consumed offsets (default every 3 seconds).
- **Environment Variable Support**: Integrated with `python-dotenv` for easy configuration.

## Prerequisites

- **Python 3.9+** (Tested with Python 3.14.0)
- **EnOS Subscription Credentials**:
  - `HOST`: Server IP/Hostname
  - `PORT`: Server Port (default 9001)
  - `ACCESS_KEY`: Your Access Key
  - `SECRET`: Your Secret Key
  - `SUB_ID`: Your Subscription ID

## Installation

1. **Clone the repository**:
   ```bash
   git clone <repository_url>
   cd data-subscription-client
   ```

2. **Create and activate a virtual environment**:
   ```bash
   python -m venv venv
   # Linux/Mac
   source venv/bin/activate
   # Windows
   venv\Scripts\activate
   ```

3. **Install dependencies**:
   ```bash
   pip install -r requirements.txt
   ```

## Usage

### 1. Configuration

Create a `.env` file (e.g., `.env.dev`) in the project root with your credentials:

```env
HOST=your_host_ip
PORT=9001
ACCESS_KEY=your_access_key
SECRET=your_secret_key
SUB_ID=your_subscription_id
```

### 2. Running the Example

Run the provided example script:

```bash
python enos_dms/sample/example.py
```

### 3. Basic Code Example

```python
from enos_dms.core.client import DataClient
import time

# Callback to handle messages
def on_message(msg):
    print(f"Topic: {msg.topic}, Partition: {msg.partition}, Offset: {msg.offset}")
    print(f"Value: {msg.value}")

# Initialize and connect
client = DataClient(
    host="your_host",
    port=9001,
    access_key="your_access_key",
    secret="your_secret",
    sub_id="your_sub_id"
)
client.on_message = on_message
client.connect()

# Keep running
try:
    while True:
        time.sleep(1)
except KeyboardInterrupt:
    client.stop()
```

## Advanced Configuration

### SSL/TLS Connection

If your server requires SSL, provide the certificate paths:

```python
SSL_CONFIG = {
    'enable_ssl': True,
    'ssl_ca_file': 'path/to/ca.crt',
    'ssl_cert_file': 'path/to/client.crt',
    'ssl_key_file': 'path/to/client.key',
    'ssl_check_hostname': False
}

client = DataClient(..., **SSL_CONFIG)
```



