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
- REST API Handling
- WebSocket Handling
- Thread-based Execution
- Exception Handling and Reconnection
Release Version | Changelog |
---|---|
0.2.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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file python_ethgas-0.2.0.tar.gz
.
File metadata
- Download URL: python_ethgas-0.2.0.tar.gz
- Upload date:
- Size: 19.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.11.3
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | cee2b86df06336451cef6307fba37afff7440a93127c3455f59f1d564a0d420e |
|
MD5 | 73223f3284a9859f44700d3ef8b0fc78 |
|
BLAKE2b-256 | a43369903966fcafbedc322c93c4134f416e27a15d40d61bff81b8cfea1ae41d |
File details
Details for the file python_ethgas-0.2.0-py3-none-any.whl
.
File metadata
- Download URL: python_ethgas-0.2.0-py3-none-any.whl
- Upload date:
- Size: 19.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.11.3
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0ebdd490717a4eba6d46069f1b4bc0bc2543b8a8b5beaca3ac26f16afe491f81 |
|
MD5 | 666ba3017d9af5c48d3bb2b79e2f0354 |
|
BLAKE2b-256 | 2c82b090106aba3584911f4bce885dc67473a6ebebd6b5d0c04cf678ee004760 |