Skip to main content

python package to connect your project with PasarGuard node go

Project description

node_bridge_py

Library to connect and use https://github.com/PasarGuard/node

Usage

pip install pasarguard-node-bridge

Library is fully async for both gRPC and REST API connection.

Example

import PasarGuardNodeBridge as Bridge
# or
import PasarGuardNodeBridge as PGNB

Creating Node

node = Bridge.create_node(
    connection=Bridge.NodeType.GRPC, # GRPC or REST
    address=address, # Node ip address or domain
    port=port, 
    client_cert=client_cert_content, # client side ssl certificate as string
    client_key=client_key_content, # client side ssl key as string
    server_ca=server_ca_content, # server side ssl key as string
    extra={}, # a dictionary to hold node data on production, optional, default: None
    )

Proto Structure

If you need to have access proto structure you can use:

from PasarGuardNodeBridge.common import service_pb2 as service

Create User

user = Bridge.create_user(
    email="jeff", 
    proxies=Bridge.create_proxy(
        vmess_id="0d59268a-9847-4218-ae09-65308eb52e08", # UUID converted to str
        vless_id="0d59268a-9847-4218-ae09-65308eb52e08", # UUID converted to str
        vless_flow="",              # Valid vless flow if is set for user (str)
        trojan_password="",         # Trojan password (str)
        shadowsocks_password="",    # Shadowsocks password (str)
        shadowsocks_method="",      # Valid shadowsocks method supported by backend
        ), 
    inbounds=[]                     # List of outbound tag, List[str]
    )

Methods

Before use any method you need to call start method and connect to node unless you will face NodeAPIError for every method

await node.start(
    config=config,  # backend config as string 
    backend_type=0, # backend type , XRAY = 0
    users=[],       # list of users you want to add to this node, will be recheck in node with config
    timeout=20,
    )

Sync Users

  • Use sync_users for small updates.
  • Use sync_users_chunked for large user lists to stream UsersChunk messages over gRPC or REST without overwhelming a single request.
await node.sync_users(users)

# Large batches
await node.sync_users_chunked(users, chunk_size=500)

Get User Stats

stats = await node.get_user_stats(
    email="noreply@donate.pasarguard.org",
    reset=True,
    timeout=10,
    )

Health

Return a Bridge.Health

health = await node.get_health()

Logs

Return a asyncio.Queue[str]

logs = await node.get_logs()

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

pasarguard_node_bridge-0.4.0.tar.gz (51.2 kB view details)

Uploaded Source

Built Distribution

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

pasarguard_node_bridge-0.4.0-py3-none-any.whl (40.2 kB view details)

Uploaded Python 3

File details

Details for the file pasarguard_node_bridge-0.4.0.tar.gz.

File metadata

  • Download URL: pasarguard_node_bridge-0.4.0.tar.gz
  • Upload date:
  • Size: 51.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.3

File hashes

Hashes for pasarguard_node_bridge-0.4.0.tar.gz
Algorithm Hash digest
SHA256 e6af5da93e0026543ce457167905b058ddf257fc57b399b8d731519a95fd1517
MD5 4059ece8b16fe2f8e55834e337b5d337
BLAKE2b-256 1236114784ee55190e541048712ebe979b59c49084a68c7595e5e088519230cf

See more details on using hashes here.

File details

Details for the file pasarguard_node_bridge-0.4.0-py3-none-any.whl.

File metadata

File hashes

Hashes for pasarguard_node_bridge-0.4.0-py3-none-any.whl
Algorithm Hash digest
SHA256 2bf02d4fad6f2e63d3124aeade366ae57591ad24f68fc4a0504a633c5780da82
MD5 6814d6c320d5d011653a74928784a796
BLAKE2b-256 08ca73f1d5ad5c9f7fcdddd2983196532bc812db092410769ae81ff0ea02150b

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