Skip to content

Commit

Permalink
Add python bindings
Browse files Browse the repository at this point in the history
  • Loading branch information
dangeross committed Apr 30, 2024
1 parent 7add324 commit 01de7bc
Show file tree
Hide file tree
Showing 8 changed files with 98 additions and 2 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

- `lib`: [lib/README.md](lib/ls-sdk-core/README.md)
- `cli`: [cli/README.md](cli/README.md)
- Bindings
- `python`: [lib/bindings-python/README.md]()

## Roadmap
- [x] Send/Recieve Lightning payments
Expand Down
5 changes: 5 additions & 0 deletions lib/ls-sdk-bindings/bindings-python/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
src/breez_liquid_sdk/*
!src/breez_liquid_sdk/__init__.py
*.egg-info
build
dist
37 changes: 37 additions & 0 deletions lib/ls-sdk-bindings/bindings-python/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# Breez Liquid SDK bindings for Python

## Usage

```
pip install breez_liquid_sdk
```

``` python
import breez_liquid_sdk
```

## Python Package

Run the GitHub workflow 'Publish Python Bindings' when creating a new release of Breez Liquid SDK.
It will create wheels for the following Python versions and Platforms and upload them to [PyPi.org](https://pypi.org/project/breez-sdk-liquid/).

### Supported Wheels

| | GNU/Linux amd64 | GNU/Linux arm64v8 | macOS x86_64 | macOS aarch64 | Windows x86_64 | Windows 32 |
|-----------------|-----------------|-------------------|--------------|---------------|----------------|------------|
| **Python 3.8** |||||||
| **Python 3.9** |||||||
| **Python 3.10** |||||||
| **Python 3.11** |||||||
| **Python 3.12** |||||||

## Building Manually

To build the package manually inside this directory use the supplied `makefile`:

``` shell
make darwin # builds the package for macos
make linux # builds the package for linux
```

The artifacts will be placed in `src/breez_liquid_sdk/`.
13 changes: 13 additions & 0 deletions lib/ls-sdk-bindings/bindings-python/makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
.PHONY: init
init:
make -C ../ init

darwin:
make -C ../ python-darwin
cp ../ffi/python/breez_liquid_sdk.py src/breez_liquid_sdk
cp ../ffi/python/libbreez_liquid_sdk_bindings.dylib src/breez_liquid_sdk

linux:
make -C ../ python-linux
cp ../ffi/python/breez_liquid_sdk.py src/breez_liquid_sdk
cp ../ffi/python/libbreez_liquid_sdk_bindings.so src/breez_liquid_sdk
3 changes: 3 additions & 0 deletions lib/ls-sdk-bindings/bindings-python/pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[build-system]
requires = ["setuptools"]
build-backend = "setuptools.build_meta"
29 changes: 29 additions & 0 deletions lib/ls-sdk-bindings/bindings-python/setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#!/usr/bin/env python

from setuptools import setup

LONG_DESCRIPTION = """# Breez Liquid SDK
Python language bindings for the [Breez Liquid SDK](https://github.com/breez/breez-sdk-liquid).
## Installing
```shell
pip install breez_liquid_sdk
```
"""

setup(
name="breez_liquid_sdk",
version="0.2.7.dev9",
description="Python language bindings for the Breez Liquid SDK",
long_description=LONG_DESCRIPTION,
long_description_content_type="text/markdown",
packages=["breez_liquid_sdk"],
package_dir={"breez_liquid_sdk": "./src/breez_liquid_sdk"},
include_package_data=True,
package_data={"breez_liquid_sdk": ["*.dylib", "*.so", "*.dll"]},
url="https://github.com/breez/breez-sdk-liquid",
author="Breez <contact@breez.technology>",
license="MIT",
has_ext_modules=lambda: True,
)
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from breez_liquid_sdk.breez_liquid_sdk import *
10 changes: 8 additions & 2 deletions lib/ls-sdk-bindings/makefile
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ init:
rustup target add aarch64-apple-darwin x86_64-apple-darwin
rustup target add aarch64-apple-ios-sim
rustup target add aarch64-linux-android armv7-linux-androideabi i686-linux-android x86_64-linux-android
rustup target add aarch64-unknown-linux-gnu x86_64-unknown-linux-gnu
@if [ $$(uname) == "Darwin" ] ; then cargo install cargo-lipo ; fi
cargo install cbindgen
cargo install cargo-ndk
Expand All @@ -30,7 +31,7 @@ clean:
test:
cargo test

all: bindings-swift bindings-android python react-native
all: bindings-swift bindings-android python-darwin react-native

## Android
android: aarch64-linux-android armv7-linux-androideabi i686-linux-android x86_64-linux-android
Expand Down Expand Up @@ -108,9 +109,14 @@ bindings-swift: ios-universal darwin-universal
rm bindings-swift/Sources/BreezLiquidSDK/breez_liquid_sdkFFI.modulemap

## Python
python: $(SOURCES)
python-linux: $(SOURCES)
cargo build --release --target $(TARGET)
cargo run --features=uniffi/cli --bin uniffi-bindgen generate src/breez_liquid_sdk.udl --no-format --language python -o ffi/python
cp ../target/$(TARGET)/release/libbreez_liquid_sdk_bindings.so ffi/python

python-darwin: darwin-universal
cargo run --features=uniffi/cli --bin uniffi-bindgen generate src/breez_liquid_sdk.udl --no-format --language python -o ffi/python
cp ../target/darwin-universal/release/libbreez_liquid_sdk_bindings.dylib ffi/python

## React Native
react-native:
Expand Down

0 comments on commit 01de7bc

Please sign in to comment.