Skip to main content

Common utilities and protobuf definitions for BharatML Stack

Project description

bharatml_commons

PyPI version Build Status Python 3.7+ Discord License

Common utilities and protobuf definitions for BharatML Stack.

Overview

bharatml_commons provides shared utilities, protobuf definitions, and base classes used across all BharatML Stack Python SDKs. This package serves as the foundation for other BharatML Stack components.

Features

  • Protobuf Schemas: Shared persist.proto and retrieve.proto definitions
  • HTTP Clients: REST API client utilities with authentication
  • Feature Metadata Client: Complete REST API client for metadata operations
  • Data Processing: Column and feature processing utilities
  • Base SDK Classes: Consistent API design across all clients
  • Code Generation: Scripts for protobuf Python file generation

Installation

pip install bharatml_commons

Quick Start

Feature Metadata Client

from bharatml_commons import FeatureMetadataClient

# Initialize client
client = FeatureMetadataClient(
    metadata_url="https://api.example.com",
    job_id="my-job",
    job_token="my-token"
)

# Get feature metadata
metadata = client.get_feature_metadata(["user_features"])
features = client.get_features({"user_id": "123"}, ["user_features"])

HTTP Client Utilities

from bharatml_commons import BharatMLHTTPClient

# Low-level HTTP client
client = BharatMLHTTPClient()
response = client.get("https://api.example.com/health")

Column and Feature Utilities

from bharatml_commons import clean_column_name, get_fgs_to_feature_mappings

# Clean column names
clean_name = clean_column_name("feature@name#1")
# Output: "feature_name_1"

# Process feature mappings
mappings = get_fgs_to_feature_mappings(feature_groups_data)

Protobuf Definitions

from bharatml_commons.proto.persist.persist_pb2 import Query, Data
from bharatml_commons.proto.retrieve.retrieve_pb2 import RetrieveQuery

# Use protobuf messages
query = Query(entity_label="user", keys_schema=["user_id"])

API Reference

FeatureMetadataClient

The main client for interacting with feature metadata APIs.

class FeatureMetadataClient:
    def __init__(self, metadata_url: str, job_id: str, job_token: str)
    def get_feature_metadata(self, feature_groups: List[str]) -> Dict
    def get_features(self, entity_keys: Dict, feature_groups: List[str]) -> Dict
    def health_check() -> Dict

Utility Functions

  • clean_column_name(name: str) -> str: Clean and normalize column names
  • generate_renamed_column(old_name: str, new_name: str) -> str: Generate renamed columns
  • get_fgs_to_feature_mappings(data: Dict) -> Dict: Process feature group mappings
  • extract_entity_info(metadata: Dict) -> Tuple: Extract entity information

HTTP Client

class BharatMLHTTPClient:
    def get(self, url: str, headers: Dict = None) -> Dict
    def post(self, url: str, data: Dict, headers: Dict = None) -> Dict
    def put(self, url: str, data: Dict, headers: Dict = None) -> Dict
    def delete(self, url: str, headers: Dict = None) -> Dict

Development

Setting up Development Environment

git clone https://github.com/Meesho/BharatMLStack.git
cd BharatMLStack/py-sdk/bharatml_commons
pip install -e .

Running Tests

pytest tests/ -v

Generating Protobuf Files

python -m bharatml_commons.proto.generate_proto

Related Packages

This package is part of the BharatML Stack ecosystem:

Contributing

We welcome contributions from the community! Please see our Contributing Guide for details on how to get started.

Community & Support

License

BharatMLStack is open-source software licensed under the BharatMLStack Business Source License 1.1.


Built with ❤️ for the ML community from Meesho
If you find this useful, ⭐️ the repo — your support means the world to us!

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

bharatml_commons-1.0.1.tar.gz (12.2 kB view details)

Uploaded Source

Built Distribution

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

bharatml_commons-1.0.1-py3-none-any.whl (18.6 kB view details)

Uploaded Python 3

File details

Details for the file bharatml_commons-1.0.1.tar.gz.

File metadata

  • Download URL: bharatml_commons-1.0.1.tar.gz
  • Upload date:
  • Size: 12.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.11.13

File hashes

Hashes for bharatml_commons-1.0.1.tar.gz
Algorithm Hash digest
SHA256 dd6865455d760e4511223838fd8474340fca294d63ec66ead89a494d3f7c789c
MD5 d98b4b2aaf87c81fd76484b2aa5fd0f9
BLAKE2b-256 e9a951831ae79f7d9e3d45d2f9a3ec0e4ef276ac6b3254e93bcedd67a529dc46

See more details on using hashes here.

File details

Details for the file bharatml_commons-1.0.1-py3-none-any.whl.

File metadata

File hashes

Hashes for bharatml_commons-1.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 383efeaa165df56c8a15aeca9413cb39643956c5e5c34bced9d3c5f89b24606e
MD5 8b70bdc38b3ed8add074e7ddaec1a138
BLAKE2b-256 6ac098db114cc8dd62f5b417624b99345e8fccb9028695037bf78b3515648d7b

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