Table of Contents
An API client library for Polygon Scan written in Python 3
WIP
This is an example of how you may give instructions on setting up your project locally. To get a local copy up and running follow these simple example steps.
Install poetry as in https://python-poetry.org/docs/
- Clone the repo
git clone https://github.com/bk62/polygon-scan-python.git- Install required python packages with poetry
cd polygon-scan-python
poetry install- (Optional) Get a free API Key at https://polygonscan.com
- (Optional) Enter your API KEY in an
.envfile
echo "export POLYGON_SCAN_API_KEY=<YOUR_API_KEY>" > .env;from polygon_scan import PolygonScan
address = "0x157B46dF4457ee4aca3137950a2E412EF368C58B"
pg_scan = PolygonScan()
balance = pg_scan.account.get_account_balance(address)
print(f"{address} balance: {balance}")
txns = pg_scan.account.get_account_normal_transactions(address)
for txn in txns[:5]:
print(txn)- Implement modules and methods for all API calls
- Handle PolygonScan errors - https://docs.polygonscan.com/support/common-error-messages
- Http client tests
- Documentation
- Docstrings
- Sphinx
- Pypi
See the open issues for a full list of proposed features (and known issues).
- Fork the Project
- Create your Feature Branch (
git checkout -b feature/AmazingFeature) - Commit your Changes (
git commit -m 'Add some AmazingFeature') - Push to the Branch (
git push origin feature/AmazingFeature) - Open a Pull Request
This project uses Betamax to mock requests by recording actual HTTP responses. The default record mode "once", raises exceptions when it encounters a new request. The first time you add a test for a new API call method:
- Export
POLYGON_SCAN_API_KEYfrom a.envfile (refer to.env.example) - Run the
run_tests.sh -k <your_test_name>script which forces Betamax to re-record ALL selected response fixtures using the API key (by temporarily setting betamax record mode to "all").
- The script sets a 2 sec delay between requests to safely respect rate limits.
- Any arguments are passed to pytest
Simply run poetry pytest to run all tests using existing fixtures.
Delete the relevant fixture file tests/fixtures/cassettes/test.<test_module_name>.<test_name> and rerun run_tests.sh if necessary.
MIT
Project Link: https://github.com/bk62/polygon-scan-python
HTTP client implementation significantly influenced by prawcore