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.4.tar.gz (20.5 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.4-py3-none-any.whl (22.0 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: platform_base_lib-0.1.4.tar.gz
  • Upload date:
  • Size: 20.5 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.4.tar.gz
Algorithm Hash digest
SHA256 ea26c327694cf40c3203f0343cd5f4d217b85898bad48e77e0e7bbfee2cb7bef
MD5 3dfbd0b7a441c3d26ca59ed2096d7663
BLAKE2b-256 3a839c1c429f96a2f415c988bfb56b856ce30e9d5febb4c53ea05c65016aee15

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for platform_base_lib-0.1.4-py3-none-any.whl
Algorithm Hash digest
SHA256 89697137f9649dffdbb2d8f50e677b572a75d8bd515e5fcd4b2a1da2ba6b120e
MD5 cf61c36c65886173316f28a772ab20ad
BLAKE2b-256 2a3420e9577aca76f3c3158fd306b1db2e2da3f7e53d8f81b3e53e83bb47abcf

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