Skip to content

Commit 92c12c0

Browse files
authored
Merge pull request #36 from nadineloepfe/publish-package
Publish package to PyPI
2 parents 8c61874 + 4c5ad2d commit 92c12c0

23 files changed

+836
-199
lines changed

.github/workflows/publish.yml

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
name: Publish to PyPI
2+
3+
on:
4+
push:
5+
tags:
6+
- 'v*.*.*'
7+
8+
jobs:
9+
build-and-publish:
10+
runs-on: ubuntu-latest
11+
steps:
12+
- uses: actions/checkout@v4
13+
14+
- name: Set up Python
15+
uses: actions/setup-python@v4
16+
with:
17+
python-version: "3.9"
18+
19+
- name: Upgrade pip
20+
run: pip install --upgrade pip
21+
22+
- name: Install build & pdm-backend
23+
run: pip install build pdm-backend
24+
25+
- name: Generate Protobuf (if needed)
26+
run: bash ./generate_proto.sh
27+
28+
- name: Build wheel and sdist
29+
run: python -m build
30+
31+
- name: Publish to PyPI
32+
uses: pypa/gh-action-pypi-publish@release/v1
33+
with:
34+
user: __token__
35+
password: ${{ secrets.PYPI_API_TOKEN }}

.gitignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,4 +31,6 @@ src/hedera_sdk_python/hapi
3131
# Pytest
3232
.pytest_cache
3333

34-
uv.lock
34+
# Lock files
35+
uv.lock
36+
pdm.lock

README.md

Lines changed: 38 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ This is a Python SDK for interacting with the Hedera Hashgraph platform. It allo
1010
## Table of Contents
1111

1212
- [Installation](#installation)
13+
- [Installing from PyPI](#installing-from-pypi)
14+
- [Installing from Source](#installing-from-source)
15+
- [Local Editable Installation](#local-editable-installation)
1316
- [Environment Setup](#environment-setup)
1417
- [Running Tests](#running-tests)
1518
- [Usage](#usage)
@@ -31,7 +34,23 @@ This is a Python SDK for interacting with the Hedera Hashgraph platform. It allo
3134

3235
## Installation
3336

34-
0. Install `uv`:
37+
### Installing from PyPI
38+
39+
The latest release of this SDK is published to PyPI. You can install it with:
40+
41+
```
42+
pip install --upgrade pip
43+
pip install hedera-sdk-python
44+
```
45+
46+
This will pull down a stable release along with the required dependencies.
47+
48+
49+
### Installing from Source
50+
51+
You can also clone the repo and install dependencies using uv:
52+
53+
1. Install `uv`:
3554

3655
`uv` is an ultra-fast Python package and project manager. It replaces `pip`, `pip-tools`, `pipx`, `poetry`, `pyenv`,
3756
`virtualenv`, and more.
@@ -48,27 +67,42 @@ brew install uv
4867

4968
Other installation methods can be found [here](https://docs.astral.sh/uv/getting-started/installation/).
5069

51-
1. Clone this repository:
70+
2. Clone this repository:
5271

5372
```bash
5473
git clone https://github.com/nadineloepfe/hedera_sdk_python.git
5574
cd hedera_sdk_python
5675
```
5776

58-
2. Install dependencies:
77+
3. Install dependencies:
5978

6079
One of the really nice features of `uv` is that it will download and manage the correct version of python and build
6180
with the correct version of python based on the `.python-version` file in the project. This means you don't have to
6281
worry about managing multiple versions of python on your machine!
6382

6483
```bash
6584
uv sync
66-
./generate_proto.sh
85+
./generate_proto.sh # if needed
6786
```
6887

6988
To update to a newer version of the protobuf libraries, edit the `generate_proto.sh` file and change the version number
7089
and then rerun it.
7190

91+
92+
### Local Editable Installation
93+
94+
For active development, you can install the repo in editable mode. That way, changes in your local code are immediately reflected when you import:
95+
96+
```
97+
git clone https://github.com/nadineloepfe/hedera_sdk_python.git
98+
cd hedera_sdk_python
99+
pip install --upgrade pip
100+
pip install -e .
101+
```
102+
103+
Now you can run example scripts like python `examples/account_create.py`, and it will import from your local hedera_sdk_python code.
104+
105+
72106
## Environment Setup
73107

74108
Before using the SDK, you need to configure your environment variables for the operator account and other credentials.

examples/account_create.py

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,21 @@
22
import sys
33
from dotenv import load_dotenv
44

5-
from hedera_sdk_python.client.client import Client
6-
from hedera_sdk_python.account.account_id import AccountId
7-
from hedera_sdk_python.crypto.private_key import PrivateKey
8-
from hedera_sdk_python.client.network import Network
9-
from hedera_sdk_python.account.account_create_transaction import AccountCreateTransaction
10-
from hedera_sdk_python.response_code import ResponseCode
5+
from hedera_sdk_python import (
6+
Client,
7+
Network,
8+
AccountId,
9+
PrivateKey,
10+
AccountCreateTransaction,
11+
ResponseCode,
12+
)
1113

1214
load_dotenv()
1315

1416
def create_new_account():
1517
network = Network(network='testnet')
1618
client = Client(network)
19+
1720
operator_id = AccountId.from_string(os.getenv('OPERATOR_ID'))
1821
operator_key = PrivateKey.from_string(os.getenv('OPERATOR_KEY'))
1922
client.set_operator(operator_id, operator_key)
@@ -24,7 +27,7 @@ def create_new_account():
2427
transaction = (
2528
AccountCreateTransaction()
2629
.set_key(new_account_public_key)
27-
.set_initial_balance(100000000) # initial balance of 1 HBAR (in tinybars)
30+
.set_initial_balance(100000000) # 1 HBAR in tinybars
2831
.set_account_memo("My new account")
2932
.freeze_with(client)
3033
)
@@ -40,7 +43,6 @@ def create_new_account():
4043
raise Exception(f"Transaction failed with status: {status_message}")
4144

4245
new_account_id = receipt.accountId
43-
4446
if new_account_id is not None:
4547
print(f"Account creation successful. New Account ID: {new_account_id}")
4648
print(f"New Account Private Key: {new_account_private_key.to_string()}")

examples/query_balance.py

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,17 @@
33
import time
44
from dotenv import load_dotenv
55

6-
from hedera_sdk_python.account.account_id import AccountId
7-
from hedera_sdk_python.crypto.private_key import PrivateKey
8-
from hedera_sdk_python.client.network import Network
9-
from hedera_sdk_python.client.client import Client
10-
from hedera_sdk_python.account.account_create_transaction import AccountCreateTransaction
11-
from hedera_sdk_python.transaction.transfer_transaction import TransferTransaction
12-
from hedera_sdk_python.query.account_balance_query import CryptoGetAccountBalanceQuery
13-
from hedera_sdk_python.hbar import Hbar
14-
from hedera_sdk_python.response_code import ResponseCode
6+
from hedera_sdk_python import (
7+
Network,
8+
Client,
9+
AccountId,
10+
PrivateKey,
11+
AccountCreateTransaction,
12+
TransferTransaction,
13+
CryptoGetAccountBalanceQuery,
14+
ResponseCode,
15+
Hbar,
16+
)
1517

1618
load_dotenv()
1719

@@ -23,21 +25,24 @@ def create_account_and_transfer():
2325
operator_key = PrivateKey.from_string(os.getenv('OPERATOR_KEY'))
2426
client.set_operator(operator_id, operator_key)
2527

28+
# Create new account
2629
new_account_private_key = PrivateKey.generate()
2730
new_account_public_key = new_account_private_key.public_key()
2831
transaction = AccountCreateTransaction(
2932
key=new_account_public_key,
30-
initial_balance=Hbar(10),
33+
initial_balance=Hbar(10), # 10 HBAR
3134
memo="New Account"
3235
).freeze_with(client)
3336
transaction.sign(operator_key)
3437
receipt = transaction.execute(client)
3538
new_account_id = receipt.accountId
3639

40+
# Check balance
3741
balance_query = CryptoGetAccountBalanceQuery().set_account_id(new_account_id)
3842
balance = balance_query.execute(client)
3943
print(f"Initial balance of new account: {balance.hbars} hbars")
4044

45+
# Transfer 5 HBAR from operator to new account
4146
transfer_amount = Hbar(5)
4247
transfer_transaction = (
4348
TransferTransaction()
@@ -51,6 +56,7 @@ def create_account_and_transfer():
5156

5257
time.sleep(2)
5358

59+
# Check updated balance
5460
updated_balance_query = CryptoGetAccountBalanceQuery().set_account_id(new_account_id)
5561
updated_balance = updated_balance_query.execute(client)
5662
print(f"Updated balance of new account: {updated_balance.hbars} hbars")

examples/query_receipt.py

Lines changed: 16 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,23 @@
22
import sys
33
from dotenv import load_dotenv
44

5-
from hedera_sdk_python.account.account_id import AccountId
6-
from hedera_sdk_python.crypto.private_key import PrivateKey
7-
from hedera_sdk_python.client.network import Network
8-
from hedera_sdk_python.client.client import Client
9-
from hedera_sdk_python.transaction.transfer_transaction import TransferTransaction
10-
from hedera_sdk_python.hbar import Hbar
11-
from hedera_sdk_python.query.transaction_get_receipt_query import TransactionGetReceiptQuery
12-
from hedera_sdk_python.response_code import ResponseCode
5+
from hedera_sdk_python import (
6+
Network,
7+
Client,
8+
AccountId,
9+
PrivateKey,
10+
TransferTransaction,
11+
Hbar,
12+
TransactionGetReceiptQuery,
13+
ResponseCode,
14+
)
1315

1416
load_dotenv()
1517

1618
def query_receipt():
1719
network = Network(network='testnet')
1820
client = Client(network)
21+
1922
operator_id = AccountId.from_string(os.getenv('OPERATOR_ID'))
2023
operator_key = PrivateKey.from_string(os.getenv('OPERATOR_KEY'))
2124
recipient_id = AccountId.from_string(os.getenv('RECIPIENT_ID'))
@@ -25,8 +28,8 @@ def query_receipt():
2528

2629
transaction = (
2730
TransferTransaction()
28-
.add_hbar_transfer(operator_id, -Hbar(amount).to_tinybars())
29-
.add_hbar_transfer(recipient_id, Hbar(amount).to_tinybars())
31+
.add_hbar_transfer(operator_id, -Hbar(amount).to_tinybars())
32+
.add_hbar_transfer(recipient_id, Hbar(amount).to_tinybars())
3033
.freeze_with(client)
3134
.sign(operator_key)
3235
)
@@ -36,14 +39,9 @@ def query_receipt():
3639
print(f"Transaction ID: {transaction_id}")
3740
print(f"Transfer transaction status: {ResponseCode.get_name(receipt.status)}")
3841

39-
40-
receipt_query = (
41-
TransactionGetReceiptQuery()
42-
.set_transaction_id(transaction_id)
43-
)
44-
45-
receipt = receipt_query.execute(client)
46-
print(f"Queried transaction status: {ResponseCode.get_name(receipt.status)}")
42+
receipt_query = TransactionGetReceiptQuery().set_transaction_id(transaction_id)
43+
queried_receipt = receipt_query.execute(client)
44+
print(f"Queried transaction status: {ResponseCode.get_name(queried_receipt.status)}")
4745

4846
if __name__ == "__main__":
4947
query_receipt()

examples/query_topic_info.py

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,16 @@
11
import os
22
from dotenv import load_dotenv
3-
from hedera_sdk_python.client.network import Network
4-
from hedera_sdk_python.client.client import Client
5-
from hedera_sdk_python.consensus.topic_id import TopicId
6-
from hedera_sdk_python.query.topic_info_query import TopicInfoQuery
7-
from hedera_sdk_python.account.account_id import AccountId
8-
from hedera_sdk_python.crypto.private_key import PrivateKey
3+
4+
from hedera_sdk_python import (
5+
Network,
6+
Client,
7+
AccountId,
8+
PrivateKey,
9+
TopicId,
10+
TopicInfoQuery,
11+
)
12+
13+
load_dotenv()
914

1015
def query_topic_info():
1116
operator_id = AccountId.from_string(os.getenv('OPERATOR_ID'))
@@ -17,7 +22,6 @@ def query_topic_info():
1722
client.set_operator(operator_id, operator_key)
1823

1924
query = TopicInfoQuery().set_topic_id(topic_id)
20-
2125
topic_info = query.execute(client)
2226
print("Topic Info:", topic_info)
2327

examples/query_topic_message.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,12 @@
22
import time
33
from datetime import datetime
44
from dotenv import load_dotenv
5-
from hedera_sdk_python.client.network import Network
6-
from hedera_sdk_python.client.client import Client
7-
from hedera_sdk_python.query.topic_message_query import TopicMessageQuery
5+
6+
from hedera_sdk_python import (
7+
Network,
8+
Client,
9+
TopicMessageQuery,
10+
)
811

912
load_dotenv()
1013

examples/token_associate.py

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,14 @@
22
import sys
33
from dotenv import load_dotenv
44

5-
from hedera_sdk_python.client.client import Client
6-
from hedera_sdk_python.account.account_id import AccountId
7-
from hedera_sdk_python.crypto.private_key import PrivateKey
8-
from hedera_sdk_python.client.network import Network
9-
from hedera_sdk_python.tokens.token_id import TokenId
10-
from hedera_sdk_python.tokens.token_associate_transaction import TokenAssociateTransaction
5+
from hedera_sdk_python import (
6+
Client,
7+
AccountId,
8+
PrivateKey,
9+
Network,
10+
TokenId,
11+
TokenAssociateTransaction,
12+
)
1113

1214
load_dotenv()
1315

@@ -17,7 +19,7 @@ def associate_token():
1719

1820
recipient_id = AccountId.from_string(os.getenv('OPERATOR_ID'))
1921
recipient_key = PrivateKey.from_string(os.getenv('OPERATOR_KEY'))
20-
token_id = TokenId.from_string('TOKEN_ID')
22+
token_id = TokenId.from_string('TOKEN_ID') # Update as needed
2123

2224
client.set_operator(recipient_id, recipient_key)
2325

0 commit comments

Comments
 (0)