Skip to main content

Unofficial EthGas client packages

Project description

python-ethgas

This is a Python3 connector for EthGas's RESTful APIs and WebSocket.

Please note that the python-ethgas package is an unofficial project and should be used at your own risk. It is NOT affiliated with the EthGas and does NOT provide financial or investment advice.

Table of Contents

Overview

The python-ethgas package is a Python3 connector that allows you to interact with the EthGas. The package utilizes threads to handle concurrent execution of REST API requests and WebSocket subscriptions. This allows for efficient handling of multiple requests and real-time data streams without blocking the main execution thread.

The connector provides a REST client that allows you to make requests to all the available REST API endpoints of the EthGas. You can perform actions such as retrieving user information, and more. It also includes a WebSocket client that enables you to subscribe to real-time data streams from EthGas. You can subscribe to channels like preconf market data, transaction data etc.

To access private endpoints and perform actions on behalf of a user, both API and Websocket client classes handle the login process and manage the authentication using the JWT access token. After you sign in to APIClient, the access token is saved and used for private requests. This access token can also be employed to log in to WsClient. Within this package, you have the option to pass the authenticated APIClient instance to the WsClient class, allowing for a private WebSocket connection.

This project is undergoing active development, ensuring that new changes to the EthGas APIs or Websocket will be promptly integrated.

For feedback or suggestions, please reach out via one of the contact methods specified in Contact.

Features

  1. REST API Handling
  2. WebSocket Handling
  3. Thread-based Execution
  4. Exception Handling and Reconnection
Release Version Changelog
0.3.0 Development release

Documentation

For more detailed information, please refer to the EthGas Developer Docs.

Quick Start

Prerequisites

python-ethgas is tested on python version: 3.11. Earlier or Later versions of Python might work, but they have not been thoroughly tested and could potentially conflict with the external web3 library.

python-ethgas utilizes web3, threading, websocket-client and requests for its methods, alongside other built-in modules. As the package utilizes the web3 library, we suggest to use version >=7.4.0 here.

Installation

To get started with the python-ethgas package, you can install it manually or via PyPI with pip:

pip install python-ethgas

Example Usage

To be able to interact with private endpoints, an ethereum EOA account (wallet address) and the corresponding private key is required. We suggest to not include those information in your source code directly but alternatively store them in environment variables. Again, please note that the python-ethgas package is an unofficial project and should be used at your own risk.

JWT access token handling is managed in this package for authentication. For interacting with private endpoints or private websocket, a login is required on the EthGas side. If you intend to establish a private WebSocket connection, please create an instance of the APIClient class, log into your account, and pass it to WsClient. If you want to only interact with public endpoints or public websocket, there is no need to supply an account address or private key. (Refer to sections 2.1a and 2.2a for more details.)

1. Import the required modules

# EthGas REST API Client
from ethgas.rest.api_client import APIClient
# EthGas Websocket Client
from ethgas.websocket.ws_client import WsClient

2. EthGas REST / WEBSOCKET client

2.1 REST client

# EthGas REST API Client
from ethgas.rest.api_client import APIClient
2.1a Public REST client
import logging
from ethgas.utils import helper
# EthGas REST API Client
from ethgas.rest.api_client import APIClient

# create logger
logger = helper.create_logger(logger_level=logging.INFO, logger_name="public_api_client")
rest_url = "<EthGas REST API URL>"
chain_id = "<Chain ID>"
# create public api client
rest = APIClient(rest_url=rest_url, chain_id=chain_id,
                 logger=logger)
2.1b Private REST client
import logging
from ethgas.utils import helper
# EthGas REST API Client
from ethgas.rest.api_client import APIClient

# create logger
logger = helper.create_logger(logger_level=logging.INFO, logger_name="private_api_client")
rest_url = "<EthGas REST API URL>"
chain_id = "<Chain ID>"
# set account address and private key
address = "<Account Address>"
private_key = "<Account Private Key>"
# create private api client
rest = APIClient(rest_url=rest_url, chain_id=chain_id,
                 account_address=address, private_key=private_key,
                 logger=logger)

2.2 WEBSOCKET client

# EthGas Websocket Client
from ethgas.websocket.ws_client import WsClient
2.2a Public WEBSOCKET client
import logging
from ethgas.utils import helper
# EthGas Websocket Client
from ethgas.websocket.ws_client import WsClient

# create logger
logger = helper.create_logger(logger_level=logging.INFO, logger_name="public_ws_client")
ws_url = "<EthGas Websocket URL>"
# create public websocket client
ws = WsClient(ws_url=ws_url, auto_reconnect_retries=5, logger=logger)
2.2b Private WEBSOCKET client
import logging
from ethgas.utils import helper
# EthGas REST API Client
from ethgas.rest.api_client import APIClient
# EthGas Websocket Client
from ethgas.websocket.ws_client import WsClient

# create logger
logger = helper.create_logger(logger_level=logging.INFO, logger_name="private_ws_client")
rest_url = "<EthGas REST API URL>"
chain_id = "<Chain ID>"
# set account address and private key
address = "<Account Address>"
private_key = "<Account Private Key>"
# create private api client
rest = APIClient(rest_url=rest_url, chain_id=chain_id,
                 account_address=address, private_key=private_key,
                 logger=logger)
ws_url = "<EthGas Websocket URL>"
# create private websocket client
ws = WsClient(ws_url=ws_url, api_client=rest, auto_reconnect_retries=5, logger=logger)

Disclaimer

This is an unofficial Python project (the "Package") and made available for informational purpose only and does not constitute financial, investment or trading advice. You acknowledge and agree to comply with the Terms of service at https://www.ethgas.com/terms-of-service. If you do not agree, please do not use this package. Any unauthorised use of the Package is strictly prohibited.

Contact

For support, suggestions or feedback please reach out to us via the following email address gaspy503@gmail.com.

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

python_ethgas-0.3.0.tar.gz (20.6 kB view details)

Uploaded Source

Built Distribution

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

python_ethgas-0.3.0-py3-none-any.whl (19.9 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for python_ethgas-0.3.0.tar.gz
Algorithm Hash digest
SHA256 e6494ddf4d38a3da892520823210288a6a7aafef6caeac166564cc8dd6290b06
MD5 c5cb4da336af36ff2d9681fab19e2f52
BLAKE2b-256 cd81b42b302474578df93863cc8e685636b79a654466133a092ff32cde48e193

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for python_ethgas-0.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 05b8b6ea3c0f276601d51b3e3c7c3774eca7897496ee34ec85e1bd55668d7c6a
MD5 6be19b165077c2043fb4bb2b6bb9a123
BLAKE2b-256 9a8aca91bf5c2b2e212b5824546074dc777d5afc0ca327968bbdaf9e392deceb

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