Metadata-Version: 2.2
Name: platform_base_lib
Version: 0.1.6
Summary: Common library for Base Setup
Home-page: https://github.com/KJBNAgtechPlatform/PlatformBaseLib
Author: Utkarsh Raj
Author-email: utkarsh.raj@kjbnlabs.in
License: MIT
Classifier: Programming Language :: Python :: 3.12
Classifier: License :: OSI Approved :: MIT License
Classifier: Operating System :: OS Independent
Requires-Python: >=3.12
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: aiomysql==0.2.0
Requires-Dist: annotated-types==0.7.0
Requires-Dist: antiorm==1.2.1
Requires-Dist: anyio==4.6.2.post1
Requires-Dist: bcrypt==4.2.1
Requires-Dist: certifi==2024.8.30
Requires-Dist: cffi==1.17.1
Requires-Dist: charset-normalizer==3.4.0
Requires-Dist: click==8.1.7
Requires-Dist: cryptography==44.0.0
Requires-Dist: db==0.1.1
Requires-Dist: dnspython==2.7.0
Requires-Dist: docutils==0.21.2
Requires-Dist: email_validator==2.2.0
Requires-Dist: fastapi==0.115.5
Requires-Dist: fastcrud==0.15.1
Requires-Dist: greenlet==3.1.1
Requires-Dist: grpcio==1.69.0
Requires-Dist: grpcio-tools==1.68.1
Requires-Dist: h11==0.14.0
Requires-Dist: idna==3.10
Requires-Dist: jaraco.classes==3.4.0
Requires-Dist: jaraco.context==6.0.1
Requires-Dist: jaraco.functools==4.1.0
Requires-Dist: jose==1.0.0
Requires-Dist: keyring==25.5.0
Requires-Dist: markdown-it-py==3.0.0
Requires-Dist: mdurl==0.1.2
Requires-Dist: more-itertools==10.5.0
Requires-Dist: nh3==0.2.19
Requires-Dist: packaging==24.2
Requires-Dist: pkginfo==1.12.0
Requires-Dist: protobuf==5.29.1
Requires-Dist: pycparser==2.22
Requires-Dist: pydantic==2.10.2
Requires-Dist: pydantic-settings==2.6.1
Requires-Dist: pydantic_core==2.27.1
Requires-Dist: Pygments==2.18.0
Requires-Dist: PyMySQL==1.1.1
Requires-Dist: python-dotenv==1.0.1
Requires-Dist: readme_renderer==44.0
Requires-Dist: requests==2.32.3
Requires-Dist: requests-toolbelt==1.0.0
Requires-Dist: rfc3986==2.0.0
Requires-Dist: rich==13.9.4
Requires-Dist: security==1.3.1
Requires-Dist: setuptools==75.6.0
Requires-Dist: sniffio==1.3.1
Requires-Dist: SQLAlchemy==2.0.36
Requires-Dist: SQLAlchemy-Utils==0.41.2
Requires-Dist: starlette==0.41.3
Requires-Dist: twine==6.0.1
Requires-Dist: typing_extensions==4.12.2
Requires-Dist: urllib3==2.2.3
Requires-Dist: uvicorn==0.32.1
Requires-Dist: wheel==0.45.1
Requires-Dist: fastapi-cors
Requires-Dist: ruamel.yaml==0.18.10
Requires-Dist: sqladmin==0.20.1
Requires-Dist: alembic==1.14.0
Provides-Extra: dev
Requires-Dist: black==23.3.0; extra == "dev"
Requires-Dist: isort==5.12.0; extra == "dev"
Requires-Dist: pre-commit==3.3.3; extra == "dev"
Dynamic: author
Dynamic: author-email
Dynamic: classifier
Dynamic: description
Dynamic: description-content-type
Dynamic: home-page
Dynamic: requires-dist
Dynamic: requires-python
Dynamic: summary

# **Platform Base Library**

`platform_base_lib` is a Python library designed as a foundational component for managing project infrastructure using gRPC protocol buffers. This project simplifies and standardizes common tasks such as communication setup, protobuf compilation, and offering shared functionalities for base setup.

## Table of Contents

1. [Features](#features)
2. [Getting Started](#getting-started)
   - [Prerequisites](#prerequisites)
   - [Installation](#installation)
     - [Install From Git](#install-from-git)
     - [Install From PyPI](#install-from-pypi)
3. [Project Commands Cheatsheet](#project-commands-cheatsheet)
   - [Protobuf File Compilation](#protobuf-file-compilation)
   - [Package Building](#package-building)
4. [Codebase Walkthrough](#codebase-walkthrough)
   - [Repository Structure](#1-repository-structure)
   - [Key Components](#2-key-components)
     - [Protobuf Management](#protobuf-management)
     - [Dependencies](#dependencies)
5. [Usage](#usage)
6. [License](#license)

---

## **Features**

- **gRPC Support**: Automatically compile `.proto` files to Python bindings for gRPC services (`*_pb2.py` and `*_pb2_grpc.py`).
- **Declarative Configuration**: Simplifies package setup using `setup.cfg` and supports easy installation and dependency management.
- **Extensible**: Provides functionality to build on top of existing gRPC infrastructure.

---

## **Getting Started**

### **Prerequisites**

Ensure you have the following installed:

- **Python** >= 3.12
- **Pip** >= 20.x.x
- Build tools for Python packaging:
  ```bash
  pip install -r requirements.txt
  ```

If you're working with the gRPC protocol buffers, you’ll also need:

- `grpcio` and `grpcio-tools` for protocol buffer compilation.

---

### **Installation**

#### **Install From Git**

You can install the `platform_base_lib` directly from the source repository:

```bash
pip install git+https://github.com/KJBNAgtechPlatform/PlatformBaseLib.git@main#egg=platform_base_lib

```

#### **Install From PyPI**

To install the library from PyPI (after publishing):

```bash
pip install platform_base_lib
```

---

## **Project Commands Cheatsheet**

### **Protobuf File Compilation**

Run the custom `generate_protos` command to compile `.proto` files into Python bindings:

```bash
python setup.py generate_protos
```

### **Package Building**

To generate source (`.tar.gz`) and wheel (`.whl`) distributions:

```bash
python setup.py sdist bdist_wheel
```

The distribution files will be located in the `dist/` folder.

---

## **Codebase Walkthrough**

### **1. Repository Structure**

```plaintext
platform_base_lib/
├── .env                        # Environment variables configuration
├── .gitignore
├── README.md                   # Project documentation
├── requirements.txt            # Project dependencies
├── main.py                   # Entry Point
├── docker-compose.yml        # Docker services configuration
│
├── base_lib/                 # Main package directory
│   ├── __init__.py
│   │
│   ├── configs/             # Configuration management
│   │   ├── __init__.py
│   │   └── config.py       # Settings and environment configuration
│   │
│   ├── infra/              # Infrastructure layer
│   │   ├── __init__.py
│   │   ├── grpc/          # gRPC related code
│   │   │   ├── __init__.py
│   │   │   ├── proto/     # Protocol buffer definitions (git submodule)
│   │   │   └── clients/   # gRPC client implementations
│   │   │
│   │   └── db/           # Database related code
│   │       ├── __init__.py
│   │       ├── mysql/    # MySQL specific implementations
│   │       └── redis/    # Redis specific implementations
│   │
│   ├── domain/           # Business logic layer
│   │   ├── __init__.py
│   │   ├── entities/     # Business entities
│   │   └── use_cases/    # Business use cases
│   │
│   ├── app/             # Application layer
│   │   ├── __init__.py
│   │   ├── services/    # Service orchestration
│   │   ├── api/        # API definitions
│   │   └── tasks/      # Background tasks
│   │
│   └── interfaces/      # Interface definitions
│       ├── __init__.py
│       ├── interactor/  # Interface implementations
│       └── db_model/    # Database models
│
├── tests/               # Test directory
│   ├── __init__.py
│   ├── unit/           # Unit tests
│   ├── integration/    # Integration tests
│   └── conftest.py     # Test configurations
│
├── docs/               # Documentation
│   └── api/           # API documentation
│
└── db-data/           # Database volume mount point (git-ignored)
    ├── mysql/         # MySQL data
    └── test-db-data/  # Test database data
```

### **2. Key Components**

#### **Protobuf Management**

All `.proto` files are stored git submodule under `base_lib/infra/grpc/proto/`. These files define gRPC services and message types.
git repo `https://github.com/KJBNAgtechPlatform/protos`

Example Usage:

```
from platform_base_lib.infra.grpc.proto import auth_pb2, auth_pb2_grpc

class MyAuthService(auth_pb2_grpc.AuthServiceServicer):
    def Login(self, request, context):
        # Process login requests
        return auth_pb2.LoginResponse(success=True)
```

#### **Dependencies**

Listed in `requirements.txt`, and must be installed for the package to work:

```plaintext
grpcio==1.56.2
grpcio-tools==1.56.2
pytest==7.4.2
numpy==1.25.0
pandas==2.1.0
```

For development dependencies, use:

```bash
pip install -e .[dev]
```

---

## **Usage**

1. **Clone the Repository:**

   ```bash
   git clone https://github.com/KJBNAgtechPlatform/PlatformBaseLib.git

   cd PlatformBaseLib
   ```

2. **Install Dependencies:**

   ```bash
   pip install -r requirements.txt
   ```

3. **Compile `.proto` Files:**

   ```bash
   python setup.py generate_protos
   ```

4. **Build and Distribute the Package:**

   ```bash
   python setup.py sdist bdist_wheel
   ```

5. **Use the Package in Another Project:**
   Install the wheel (`.whl`) file or use Git for installation:
   ```bash
   pip install git+https://github.com/KJBNAgtechPlatform/PlatformBaseLib.git@main#egg=platform_base_lib
   ```

---

## **License**

This library is licensed under the MIT License. See `LICENSE` for details.
