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/
│
├── src/                        
│   └── platform_base_lib/      # Main library directory containing application logic
│       ├── infra/              # Infrastructure layer for external systems
│       │   ├── grpc/           # Handles gRPC-specific implementation and setups
│       │   │   ├── proto/      # Folder containing .proto definitions and gRPC-related resources
│       │   │   └── clients/    # Folder for gRPC clients and related configurations
│       │   └── db/             # Database-related configurations and utilities
│       ├── domain/             # Domain layer for core business logic
│       │   ├── entities/       # Folder containing business entity definitions
│       │   └── use_cases/      # Folder for defining business-specific use cases
│       ├── application/        # Application services and orchestrations
│       │   ├── services/       # Service classes coordinating use cases and interfaces
│       │   └── tasks/          # Folder for application-level background tasks or operations
│       └── interfaces/         # Interfaces for APIs or external contracts
│           ├── api/            # Web or gRPC APIs definition
│           └── repository/     # Repository pattern implementations
├── README.md                   # Project documentation
├── .env                        # Environment variables file for configuration
├── requirements.txt            # Lists all dependencies required for the package
├── setup.py                    # Implements setup script for building and distributing the package
├── setup.cfg                   # Declarative configuration file for package metadata
└── pyproject.toml              # Build-system configuration file (PEP 518 support)

2. Key Components

Protobuf Management

All .proto files are stored under platform_base_lib/infra/grpc/proto/. These files define gRPC services and message types.

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

python setup.py generate_protos

This generates:

  • auth_pb2.py: Contains gRPC messages.
  • auth_pb2_grpc.py: Contains gRPC service stubs.

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.5.tar.gz (18.6 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.5-py3-none-any.whl (19.2 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: platform_base_lib-0.1.5.tar.gz
  • Upload date:
  • Size: 18.6 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.5.tar.gz
Algorithm Hash digest
SHA256 10616170a3eea6a5c04a6e34714d499f3203975104223a44cdffe57a48cf7cc1
MD5 6842e7db74d04a3a3924014c99e2d497
BLAKE2b-256 0e12897fa7b5bebae6842e5118ef688ba19704a28a4695ab44dee34c5264310b

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for platform_base_lib-0.1.5-py3-none-any.whl
Algorithm Hash digest
SHA256 a3b06fb64755bc7ea25d2953fe011c6c9906d0dff921ace35f438f9dde393b18
MD5 6a3e9c8ca982935a54cec9467192b717
BLAKE2b-256 af42b6e27bc9b373ec345fb4357df61b366860aeb3fa68587019d3d33348b937

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