Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
50cc13d
chore: update project progress
elijah0kello Feb 11, 2025
64ee7e0
Merge branch 'main' of github.com:elijah0kello/open-payments-python-sdk
elijah0kello Feb 11, 2025
2130dd8
Make fetch_spec.sh runnable from any directory
Kasweka1 Jun 3, 2025
e9e8dcf
Merge branch 'main' of github.com:elijah0kello/open-payments-python-sdk
elijah0kello Jun 13, 2025
baa2e9f
created requirements.txt
Kasweka1 Jun 16, 2025
9b725c3
feat: http signature implementations
Kasweka1 Jun 17, 2025
61ba6c9
feat: implemented gnap functionality
elijah0kello Jun 17, 2025
6a2ccd3
chore: removed requirements.txt
Kasweka1 Jun 17, 2025
8719193
ci: added test workflow for github actions
elijah0kello Jun 17, 2025
adc8124
ci: fixed failing test workflow
elijah0kello Jun 17, 2025
777b019
ci: run unit tests only
elijah0kello Jun 17, 2025
0a20138
ci: run tests for python 3.13
elijah0kello Jun 17, 2025
94cd07f
ci: run unit tests only
elijah0kello Jun 17, 2025
d327d72
Merge pull request #1 from Kasweka1/ft/http-signatures
elijah0kello Jun 17, 2025
188cc0d
chore: added unit test files
elijah0kello Jun 17, 2025
90c9d37
Merge branch 'ft/gnap-utils' of github.com:elijah0kello/open-payments…
elijah0kello Jun 17, 2025
00885a3
chore: fixed whitespace issues
elijah0kello Jun 17, 2025
250d03b
feat: updated readme docs
Kasweka1 Jun 17, 2025
25b523c
chore: added get signed headers function
elijah0kello Jun 17, 2025
3056025
Merge pull request #2 from Kasweka1/ft/set-up-documentation
elijah0kello Jun 17, 2025
a2aed05
docs: updated documentation
elijah0kello Jun 17, 2025
f56b513
feat: added http signatures to resource and grant classes
elijah0kello Jun 17, 2025
2ca863f
fix: fixed failiing wallet integration tests
elijah0kello Jun 18, 2025
a813747
chore: put client in sdk folder
elijah0kello Jun 18, 2025
de3c090
docs: added documentation for sdk
elijah0kello Jun 18, 2025
a43785c
chore: fix failing tests
elijah0kello Jun 18, 2025
cb07c23
fix: fixed typo in OpenPaymentsClient class name
elijah0kello Jun 19, 2025
f040f2a
docs: updated docs
elijah0kello Jun 19, 2025
75f7708
chore: updated test folder in ci
elijah0kello Jun 22, 2025
7b21489
feat: fix failing grant requests
elijah0kello Jun 22, 2025
782ec63
chore: wrote unit and integration tests
elijah0kello Jun 22, 2025
aa4493c
docs: added usage docs
elijah0kello Jun 22, 2025
293b0d8
chore: remove unused imports
elijah0kello Jun 22, 2025
973bc42
Update README.md
elijah0kello Jul 17, 2025
9303f8e
Update README.md
elijah0kello Jul 17, 2025
29f52bd
chore: addressed issues in PR comments
elijah0kello Jul 26, 2025
3f468f5
ci: fix failing pipeline
elijah0kello Jul 26, 2025
28ad4f0
ci: fixed ci error and add windows support and set python supported v…
elijah0kello Jul 26, 2025
81429ee
fix: fixed python versions and synced lock file
elijah0kello Jul 26, 2025
c339b91
ci: add poetry to path on windows runer
elijah0kello Jul 26, 2025
27b7106
ci: add poetry to path on windows
elijah0kello Jul 26, 2025
bbfbe66
ci: debug windows installation dir
elijah0kello Jul 26, 2025
a8ab4ee
ci: verify poetry is installed and create envs in new step
elijah0kello Jul 26, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
67 changes: 67 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
name: Test Python open payments sdk

on:
push:
branches:
- '**'
pull_request:
branches:
- '**'

jobs:
test:
runs-on: ${{ matrix.os }}

strategy:
matrix:
os: [ubuntu-latest, windows-latest]
python-version: ["3.10","3.11","3.12","3.13"]

steps:
- name: Checkout code
uses: actions/checkout@v3

- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}

- name: Setup Poetry on Windows
if: runner.os == 'Windows'
run: |
(Invoke-WebRequest -Uri https://install.python-poetry.org -UseBasicParsing).Content | py -
echo "$env:APPDATA\Python\Scripts" >> $env:GITHUB_PATH

- name: Verify Poetry and create env on Windows
if: runner.os == 'Windows'
run: |
poetry --version
poetry config virtualenvs.create false


- name: Setup Poetry on Ubuntu
if: runner.os != 'Windows'
run: |
curl -sSL https://install.python-poetry.org | python3 -
echo "$HOME/.local/bin" >> $GITHUB_PATH
poetry config virtualenvs.create false

- name: Install dependencies
run: |
poetry install --no-interaction --no-root
poetry install --only dev

- name: Run Unit Tests
run: |
poetry run pytest tests/unit/

audit:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Install dependencies
run: |
python3 -m pip install . # assumes dependencies declared in pyproject.toml
python3 -m pip install pip-audit
- name: Run pip-audit
run: pip-audit .
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -170,3 +170,4 @@ poetry.toml
pyrightconfig.json

# End of https://www.toptal.com/developers/gitignore/api/python
privkey.pem
121 changes: 119 additions & 2 deletions README.md
Comment thread
elijah0kello marked this conversation as resolved.
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,130 @@ An Open Payments server runs two sub-systems, a resource server which exposes AP

## Local development

### Dependencies

- Python >= 3.11

To install python visit [Python Download](https://www.python.org/downloads/)

- Poetry
To install poetry visit [Poetry Documentation](https://python-poetry.org/docs/).

### Installation

1. Activate your virtual emvironment. No need to create one, Poetry creates one.
Read [managing environments in Poetry](https://python-poetry.org/docs/managing-environments/).

2. Install the dependencies in the poetry.lock

```
> poetry install
```
Comment thread
elijah0kello marked this conversation as resolved.

## Usage

To use this SDK, you will first need to install it in your project. Currently, you will need to build from source but once it is hosted on PyPi you will be able to install it with `pip`.

```bash
python3 -m pip install open-payments-python-sdk #currently not setup
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you are running poetry install why do you need to explicitly install the module?

```

## Installing from source

Clone the repository

```bash
git clone https://github.com/interledger/open-payments-python-sdk.git
cd open-payments-python-sdk
```

Build the package

```bash
poetry build
```

After running this command, the wheel package will be written to the `dist/` folder in the repo you just cloned

Install it in your project

```bash
pip install </path/to/>open-payments-python-sdk/dist/open_payments_sdk-0.1.0-py3-none-any.whl
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We do have a poetry based setup, there is no need to point to a pinned version of the wheel file.

```

# Initialising the Client

To create a client you can do so by importing the `OpenPaymentsClient` defined in the [`client`](./src/client/client.py) module and instantiating it.

```python
from open_payments_sdk.client.client import OpenPaymentsClient

with open("privkey.pem","r",encoding="utf_8") as privkey:
private_key = privkey.read()

op_client = OpenPaymentsClient(keyid="27b4f8d2-746c-4522-b3f0-874ca15bfe65",private_key=private_key)
```

The client is to be created after you have created a key pair and have obtained the `kid` and `private_key`

Some helper functions have been created to ease key pair creation. A class called `KeyManager` has been created and it provides functions to create a key pair and load a private key from UTF-8 string. It also returns an object that has information to be registered at the AS when registering the public key.

```python
import json
from open_payments_sdk.gnap_utils.keys import KeyManager

key_manager = KeyManager()
key_pair = key_manager.generate_key_pair() # generate key pair

with open("privkey.pem", "w",encoding="utf_8") as pem_file: # save private key to file
pem_file.write(key_pair.private_key_pem)


with open("jwks.json","w", encoding="utf_8") as jwks_file: # save jwks.json file
jwks_file.write(json.dumps(key_pair.jwks.keys[0].__dict__))


with open("privkey.pem", "r", encoding="utf_8") as privkey: # load private key from file system
private_key = privkey.read()

private_key = key_manager.load_ed25519_private_key_from_pem(
private_key
) # load private key fron file utf_8 string

public_key = private_key.public_key() # derive public key from private key
```

## Wallets

You can use the created client to interact with the resource server. In this case we will use it to interact with a wallet address to get the wallet address details and jwks.json

```python
#get wallet address
wallet_address_details = op_client.wallet.get_wallet_address("https://ilp.interledger-test.dev/elijahokellosalary")

# Response
{'id': AnyUrl('https://ilp.interledger-test.dev/elijahokellosalary'), 'publicName': 'elijahokellosalary', 'assetCode': AssetCode(root='USD'), 'assetScale': AssetScale(root=2), 'authServer': AnyUrl('https://auth.interledger-test.dev/'), 'resourceServer': AnyUrl('https://ilp.interledger-test.dev/')}

```

Get Wallet jwks

```python
#get wallet jwks
wallet_jwks = op_client.wallet.get_keys("https://ilp.interledger-test.dev/elijahokellosalary")

# Response
{'keys': []}

```

## Grants

You can use the created client to request a grant from the authorization server. In this case we will use it to request a grant for an incoming payment resource. Check the [fixtures](./tests/conftest.py) file to see the request body.

```python
wallet = op_client.wallet.get_wallet_address("https://ilp.interledger-test.dev/5c327379")
grant_response = op_client.grants.post_grant_request(grant_request=grant_req_dto,auth_server_endpoint=str(wallet.authServer))

# Response
{'access_token': {'access': [{'actions': ['create', 'read'], 'identifier': 'https://ilp.interledger-test.dev/5c327379', 'type': 'incoming-payment'}], 'value': '2E6F040D518B6F1A0883', 'manage': 'https://auth.interledger-test.dev/token/dad85db0-804d-4778-bf78-33eb5f81d86e', 'expires_in': 600}, 'continue': {'access_token': {'value': '3A088F83D39BDCDEC995'}, 'uri': 'https://auth.interledger-test.dev/continue/d2bb7a46-8cd9-4dde-83e2-821353b50579'}}

```
Loading