Skip to main content

A production-grade Python SDK for Hyperledger Fabric Gateway

Project description

🚀 moe_fabric_gateway

专为 Hyperledger Fabric (v2.4+) Gateway 打造的生产级、原生异步 Python SDK。

Python Version License Build Status Coverage

moe_fabric_gateway 提供了一种优雅、轻量且稳健的方式与 Hyperledger Fabric 网络进行交互。它专为现代 Python 的 asyncio 模式精心设计,旨在为 Web3 和企业级区块链开发者提供卓越的开发者体验(DX)。


✨ 核心特性

  • ⚡️ 原生异步 (asyncio):自底向上采用 grpc.aio 构建,实现完全的非阻塞 I/O。告别阻塞调用和线程池瓶颈。
  • 🔒 安全的离线证书管理:通过离线的签名器 (Signer) 架构实现私钥 (Private Key) 的绝对隔离。私钥永远不会离开应用内存,也绝不会在网络中传输。
  • 🪶 极轻量级架构:零 protoc 依赖。针对核心交易采用手写的、极其高效的 Protobuf 序列化,体积小巧,避免了 grpcio-tools 生成文件的臃肿。
  • 🛡️ 企业级可靠性:强制的 TLS 安全通道、内置的 gRPC 异常重试机制、Keep-Alive 参数调优,以及针对事件监听的流断线自动重连。

⚡ 快速预览

体验 async/await 驱动的极简 API。以下是实例化网关 (Gateway) 和评估交易 (Evaluate Transaction) 的代码示例:

import asyncio
from fabric_gateway import Gateway, GatewayClient, TlsConfig, DefaultIdentity, DefaultSigner

async def main() -> None:
    # 1. 初始化身份 (Identity) 与离线签名器 (Signer)
    identity = DefaultIdentity(msp_id="Org1MSP", cert_path="cert.pem")
    signer = DefaultSigner(key_path="key.pem")

    # 2. 配置安全的 gRPC 通道 (TLS)
    tls_config = TlsConfig(tls_ca_cert_path="tls-cert.pem")
    client = GatewayClient(endpoint="localhost:7051", tls_config=tls_config)

    # 3. 连接到网关 (Gateway) 并与智能合约交互
    async with Gateway(client, identity, signer) as gateway:
        network = gateway.get_network("mychannel")
        contract = network.get_contract("basic")

        # 评估交易 (Evaluate Transaction) - 用于查询
        print("--> 评估交易: ReadAsset")
        result = await contract.evaluate_transaction("ReadAsset", "asset1")
        print(f"结果: {result.decode('utf-8')}")

if __name__ == "__main__":
    asyncio.run(main())

📚 目录导航

准备好深入了解了吗?请查阅 docs/ 目录下的深度指南:

  • 📖 快速入门指南:连接网关、查询以及提交交易 (Submit Transaction) 的详细分步教程。
  • 🛠️ 核心 API 文档:核心 API(包含身份 Identity、网关 Gateway、合约交互、背书 Endorsement 等)的详细契约说明。
  • 🌍 English Documentation: Documentation for English-speaking developers.

🤖 声明:本项目部分基础代码与文档由 AI Agent 辅助生成,并经过人工严格审计。

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

moe_fabric_gateway-0.0.6.tar.gz (54.2 kB view details)

Uploaded Source

Built Distribution

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

moe_fabric_gateway-0.0.6-py3-none-any.whl (65.0 kB view details)

Uploaded Python 3

File details

Details for the file moe_fabric_gateway-0.0.6.tar.gz.

File metadata

  • Download URL: moe_fabric_gateway-0.0.6.tar.gz
  • Upload date:
  • Size: 54.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for moe_fabric_gateway-0.0.6.tar.gz
Algorithm Hash digest
SHA256 f05600154a7dcbbaa33ed303799d42a0b4e05d50bdb3d690c910298bb47eb2d0
MD5 81aff81ccd6c2fdd1907b7ca5677dc20
BLAKE2b-256 def50425dd2b524177e514805ece062ef595d97d716888b62f0564fed92ff8c6

See more details on using hashes here.

Provenance

The following attestation bundles were made for moe_fabric_gateway-0.0.6.tar.gz:

Publisher: publish.yml on N791/moe-fabric-gateway-python-sdk

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file moe_fabric_gateway-0.0.6-py3-none-any.whl.

File metadata

File hashes

Hashes for moe_fabric_gateway-0.0.6-py3-none-any.whl
Algorithm Hash digest
SHA256 b66d1feed38a896c090c0a1184fcceb4bee043b63db7bc0bae1c7f12170efba0
MD5 d431983282d3464c907d55a38e02ca5d
BLAKE2b-256 79775475b5dbe910a6f03d7c55476ebcec693c0fe02d057aeb0135d0df290edd

See more details on using hashes here.

Provenance

The following attestation bundles were made for moe_fabric_gateway-0.0.6-py3-none-any.whl:

Publisher: publish.yml on N791/moe-fabric-gateway-python-sdk

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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