Skip to main content

Python gRPC client for Your Service

Project description

Messaging Core Python SDK

PyPI version Python Version License: MIT

Python gRPC client for the Messaging Core service, providing easy access to messaging functionality.

Installation

Prerequisites

  • Python 3.8 or higher
  • gRPC and Protocol Buffers support

Install from PyPI

pip install messaging-core

Quick Start

Basic Usage

import grpc
from messaging_core import users, users_pb2_grpc

# Set up the gRPC channel (replace with your server address)
channel = grpc.insecure_channel('your-server-address:50051')

# Initialize the client
users_client = users_pb2_grpc.UsersServiceStub(channel)

# Example: Get user information
try:
    user_request = users.GetUserRequest(user_id="123")
    response = users_client.GetUser(user_request)
    print(f"User found: {response.user.name}")
except grpc.RpcError as e:
    print(f"Error: {e.code()}: {e.details()}")

Available Services

The SDK provides the following service clients:

  • Users Service: users_pb2_grpc.UsersServiceStub
  • Auth Service: auth_pb2_grpc.AuthServiceStub
  • Messaging Service: messaging_pb2_grpc.MessagingServiceStub
  • Conversation Service: conversation_pb2_grpc.ConversationServiceStub
  • Attachment Service: attachment_pb2_grpc.AttachmentServiceStub

Example: Sending a Message

import grpc
from messaging_core import messaging, messaging_pb2_grpc

channel = grpc.insecure_channel('your-server-address:50051')
messaging_client = messaging_pb2_grpc.MessagingServiceStub(channel)

message = {
    'sender_id': 'user123',
    'conversation_id': 'conv456',
    'content': 'Hello from Python SDK!',
    'type': 'TEXT'
}

response = messaging_client.SendMessage(
    messaging.SendMessageRequest(message=message)
)
print(f"Message sent with ID: {response.message_id}")

Error Handling

All gRPC errors are raised as grpc.RpcError. You can handle them like this:

try:
    # Your gRPC call here
    response = client.YourMethod(request)
except grpc.RpcError as e:
    if e.code() == grpc.StatusCode.NOT_FOUND:
        print("Requested resource not found")
    elif e.code() == grpc.StatusCode.UNAUTHENTICATED:
        print("Authentication failed")
    else:
        print(f"RPC failed: {e.code()}: {e.details()}")

Development

For development and contributing, you'll need:

Setup

  1. Clone the repository:

    git clone https://github.com/alijkdkar/Messaging-Core.git
    cd Messaging-Core/docs/sdk/python
    
  2. Install dependencies:

    poetry install
    

Generating gRPC Code

To regenerate the gRPC code from the .proto files:

./scripts/generate_sdk.sh

Running Tests

pytest tests/

Building the Package

python -m build

Publishing to PyPI

  1. Build the package:

    python -m build
    
  2. Upload to PyPI:

    twine upload dist/*
    

License

This project is licensed under the MIT License - see the LICENSE file 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

messaging_core-0.1.0.tar.gz (16.3 kB view details)

Uploaded Source

Built Distribution

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

messaging_core-0.1.0-py3-none-any.whl (22.1 kB view details)

Uploaded Python 3

File details

Details for the file messaging_core-0.1.0.tar.gz.

File metadata

  • Download URL: messaging_core-0.1.0.tar.gz
  • Upload date:
  • Size: 16.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.10.5

File hashes

Hashes for messaging_core-0.1.0.tar.gz
Algorithm Hash digest
SHA256 afff81aa7a77246006c572bd6ff8461f7229f8aea5a8f1a021fc48d83805245e
MD5 ea74c5ba4e339ba4c289194d3e5b7cbf
BLAKE2b-256 2996873314a0d3cb35b107eb9a25b70f609fa83a3641f0379819058e325c0836

See more details on using hashes here.

File details

Details for the file messaging_core-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: messaging_core-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 22.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.10.5

File hashes

Hashes for messaging_core-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 37efa5638c2839847817acadf2936a6cd6bd3efbbba799e892bd40f61b35a797
MD5 d310f735fdf28c9fbe537a804c86d14d
BLAKE2b-256 6910576b8a945aa2cf7aa4b07af2fc26083c690cf29cce4b0bd8626a2c4bef93

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