Skip to main content

a3grpc is a simple wrapper around grpc to make it easier to use.

Project description

a3grpc

English | 简体中文

a3grpc is a simple wrapper around grpc to make it easier to use.

1. Introduction

Server

  • Similar to Django, one API corresponds to one View. Inherit the base class View and return error information to the client by throwing exceptions.
  • Use Servicer to contain the relevant Views.
  • Write servicer_mappings. Similar to Django urls, multiple Servicers can be configured.
  • Prepare the following configuration conf and call run_grpc_server or run_grpc_server_with_multiprocessing to start the service.
conf = {
    # Optional. Number of processes. It will be used when using run_grpc_server_with_multiprocessing. If not specified, it will be the cpu_count.
    "process_count": 3,
    # Required.
    "host": "127.0.0.1",
    # Required.
    "port": 50051,
    # Required. Number of workers.
    "max_workers": 10,
    # Required. Number of concurrent connections.
    "maximum_concurrent_rpcs": 100,
    # Required. Mapping between add_func and Servicer.
    "servicer_mappings": "app.mappings.servicer_mappings",
    # Optional. SSL certificate.
    "server_key": "/data/ssl/server-key.pem",
    "server_cert": "/data/ssl/server.pem",
    "ca_cert": "/data/ssl/ca.pem",
    # Optional. Graceful shutdown seconds.
    "graceful_shutdown_seconds": 10,
    # Optional. Underlying configuration, details:https://grpc.github.io/grpc/core/group__grpc__arg__keys.html
    "options": (
        ("grpc.keepalive_time_ms", 10000),
        ("grpc.keepalive_timeout_ms", 5000),
        ("grpc.keepalive_permit_without_calls", True),
        ("grpc.http2.max_pings_without_data", 0),
        ("grpc.http2.min_ping_interval_without_data_ms", 5000),
        ("grpc.max_receive_message_length", 20 * 1024 * 1024),
        ("grpc.max_send_message_length", 20 * 1024 * 1024),
    ),
    # Optional. Similar to Django middlewares.
    "interceptors": [
        "app.interceptors.Interceptor",
    ],
    # Optional. Customize the status code.
    "patch_status_code": {
        "client_site_error_code": 499,
        "server_site_error_code": 599,
    }
}

Client

  • Inherit BaseClient and implement target APIs
  • If the server return an exception, it will automatically throw the exception instance.

2. Usage

Install

pip install a3grpc

Examples

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

a3grpc-0.3.0.tar.gz (9.3 kB view details)

Uploaded Source

Built Distribution

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

a3grpc-0.3.0-py3-none-any.whl (10.8 kB view details)

Uploaded Python 3

File details

Details for the file a3grpc-0.3.0.tar.gz.

File metadata

  • Download URL: a3grpc-0.3.0.tar.gz
  • Upload date:
  • Size: 9.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.11.2

File hashes

Hashes for a3grpc-0.3.0.tar.gz
Algorithm Hash digest
SHA256 834369efb02646db773e2b3b746594bbaaafa8e171e5c47385e830bacce8e663
MD5 823d4c6d57820171407b92ffe6f66a80
BLAKE2b-256 9948c46b01d2e32819ccc60f6924216668e60f9c6d90b89f0d133a51877bb091

See more details on using hashes here.

File details

Details for the file a3grpc-0.3.0-py3-none-any.whl.

File metadata

  • Download URL: a3grpc-0.3.0-py3-none-any.whl
  • Upload date:
  • Size: 10.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.11.2

File hashes

Hashes for a3grpc-0.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 b9951a5418d2b5ebd03a2216fde77ebf81eda090cbe009894d2189eabd5c5f37
MD5 b7293abef9c9790f8f765c0e4ac24694
BLAKE2b-256 467b295712644b6d1b03817b71f89f97d398004f6fd7f6d8c549159cf75cde93

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