Skip to main content

Common library for Base Setup

Project description

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
  2. Getting Started
  3. Project Commands Cheatsheet
  4. Codebase Walkthrough
  5. Usage
  6. 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:
    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:

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):

pip install platform_base_lib

Project Commands Cheatsheet

Protobuf File Compilation

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

python setup.py generate_protos

Package Building

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

python setup.py sdist bdist_wheel

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


Codebase Walkthrough

1. Repository Structure

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:

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:

pip install -e .[dev]

Usage

  1. Clone the Repository:

    git clone https://github.com/KJBNAgtechPlatform/PlatformBaseLib.git
    
    cd PlatformBaseLib
    
  2. Install Dependencies:

    pip install -r requirements.txt
    
  3. Compile .proto Files:

    python setup.py generate_protos
    
  4. Build and Distribute the Package:

    python setup.py sdist bdist_wheel
    
  5. Use the Package in Another Project: Install the wheel (.whl) file or use Git for installation:

    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.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

platform_base_lib-0.1.6.tar.gz (20.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

platform_base_lib-0.1.6-py3-none-any.whl (24.7 kB view details)

Uploaded Python 3

File details

Details for the file platform_base_lib-0.1.6.tar.gz.

File metadata

  • Download URL: platform_base_lib-0.1.6.tar.gz
  • Upload date:
  • Size: 20.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.0.1 CPython/3.12.8

File hashes

Hashes for platform_base_lib-0.1.6.tar.gz
Algorithm Hash digest
SHA256 41eadea652fb85441bda76b231f304f041b3201eb0da1db4fbe68320b74362c8
MD5 b8a89b8209590e21f70569a4c4eaa900
BLAKE2b-256 0a3674a7c376bd48d27e6de603c36a3ef0b3825feec7848385dcfb222ddea0f1

See more details on using hashes here.

File details

Details for the file platform_base_lib-0.1.6-py3-none-any.whl.

File metadata

File hashes

Hashes for platform_base_lib-0.1.6-py3-none-any.whl
Algorithm Hash digest
SHA256 b490c6ab480dc0c87e2cf29b7c72f30c8c15c59d29c1e7154d3b28a25b19c234
MD5 fa21ddff758ae65fbed91e4a6c8f530e
BLAKE2b-256 4304502a77cd724c9c7af90cd75a873206196024ce13e07f010cd4743c768798

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page