speedapi-lib 0.1.1__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- speedapi_lib-0.1.1/PKG-INFO +57 -0
- speedapi_lib-0.1.1/README.md +40 -0
- speedapi_lib-0.1.1/setup.cfg +4 -0
- speedapi_lib-0.1.1/setup.py +31 -0
- speedapi_lib-0.1.1/speedapi_lib/__init__.py +0 -0
- speedapi_lib-0.1.1/speedapi_lib/api_client.py +38 -0
- speedapi_lib-0.1.1/speedapi_lib/config.py +14 -0
- speedapi_lib-0.1.1/speedapi_lib/invoice.py +18 -0
- speedapi_lib-0.1.1/speedapi_lib.egg-info/PKG-INFO +57 -0
- speedapi_lib-0.1.1/speedapi_lib.egg-info/SOURCES.txt +14 -0
- speedapi_lib-0.1.1/speedapi_lib.egg-info/dependency_links.txt +1 -0
- speedapi_lib-0.1.1/speedapi_lib.egg-info/entry_points.txt +2 -0
- speedapi_lib-0.1.1/speedapi_lib.egg-info/requires.txt +4 -0
- speedapi_lib-0.1.1/speedapi_lib.egg-info/top_level.txt +2 -0
- speedapi_lib-0.1.1/tests/__init__.py +0 -0
- speedapi_lib-0.1.1/tests/test_sample.py +12 -0
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
Metadata-Version: 2.1
|
|
2
|
+
Name: speedapi_lib
|
|
3
|
+
Version: 0.1.1
|
|
4
|
+
Summary: A Python library for interacting with Speed API and managing Lightning Network invoices
|
|
5
|
+
Home-page: https://github.com/furkankoykiran/speedapi_lib
|
|
6
|
+
Author: Furkan Köykıran
|
|
7
|
+
Author-email: furkankoykiran@gmail.com
|
|
8
|
+
Classifier: Programming Language :: Python :: 3
|
|
9
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
10
|
+
Classifier: Operating System :: OS Independent
|
|
11
|
+
Requires-Python: >=3.7
|
|
12
|
+
Description-Content-Type: text/markdown
|
|
13
|
+
Requires-Dist: requests
|
|
14
|
+
Requires-Dist: pydantic
|
|
15
|
+
Requires-Dist: pydantic-settings
|
|
16
|
+
Requires-Dist: bolt11
|
|
17
|
+
|
|
18
|
+
# speedapi_lib
|
|
19
|
+
|
|
20
|
+
This is a Python library for interacting with the Speed API and managing Lightning Network invoices.
|
|
21
|
+
|
|
22
|
+
## Installation
|
|
23
|
+
|
|
24
|
+
You can install this library from your private GitHub repository:
|
|
25
|
+
|
|
26
|
+
```bash
|
|
27
|
+
pip install git+https://github.com/furkankoykiran/speedapi_lib.git@main
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
## Usage
|
|
31
|
+
|
|
32
|
+
```python
|
|
33
|
+
from speedapi_lib.api_client import SpeedAPIClient
|
|
34
|
+
from speedapi_lib.invoice import Invoice
|
|
35
|
+
from speedapi_lib.config import AppConfig
|
|
36
|
+
|
|
37
|
+
config = AppConfig()
|
|
38
|
+
|
|
39
|
+
client = SpeedAPIClient(secret_key=config.SECRET_KEY, base_url=config.BASE_URL)
|
|
40
|
+
balance = client.get_balance_sats()
|
|
41
|
+
print(f"Balance: {balance} SATS")
|
|
42
|
+
|
|
43
|
+
invoice_str = "your_invoice_here"
|
|
44
|
+
invoice = Invoice(invoice_str)
|
|
45
|
+
invoice_info = invoice.get_info()
|
|
46
|
+
print(invoice_info)
|
|
47
|
+
|
|
48
|
+
if balance >= invoice_info["amount"]:
|
|
49
|
+
payment = client.pay_invoice(invoice_str)
|
|
50
|
+
print(payment)
|
|
51
|
+
else:
|
|
52
|
+
print("Insufficient balance to pay invoice")
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
## License
|
|
56
|
+
|
|
57
|
+
This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
# speedapi_lib
|
|
2
|
+
|
|
3
|
+
This is a Python library for interacting with the Speed API and managing Lightning Network invoices.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
You can install this library from your private GitHub repository:
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
pip install git+https://github.com/furkankoykiran/speedapi_lib.git@main
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
## Usage
|
|
14
|
+
|
|
15
|
+
```python
|
|
16
|
+
from speedapi_lib.api_client import SpeedAPIClient
|
|
17
|
+
from speedapi_lib.invoice import Invoice
|
|
18
|
+
from speedapi_lib.config import AppConfig
|
|
19
|
+
|
|
20
|
+
config = AppConfig()
|
|
21
|
+
|
|
22
|
+
client = SpeedAPIClient(secret_key=config.SECRET_KEY, base_url=config.BASE_URL)
|
|
23
|
+
balance = client.get_balance_sats()
|
|
24
|
+
print(f"Balance: {balance} SATS")
|
|
25
|
+
|
|
26
|
+
invoice_str = "your_invoice_here"
|
|
27
|
+
invoice = Invoice(invoice_str)
|
|
28
|
+
invoice_info = invoice.get_info()
|
|
29
|
+
print(invoice_info)
|
|
30
|
+
|
|
31
|
+
if balance >= invoice_info["amount"]:
|
|
32
|
+
payment = client.pay_invoice(invoice_str)
|
|
33
|
+
print(payment)
|
|
34
|
+
else:
|
|
35
|
+
print("Insufficient balance to pay invoice")
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
## License
|
|
39
|
+
|
|
40
|
+
This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
from setuptools import setup, find_packages
|
|
2
|
+
|
|
3
|
+
setup(
|
|
4
|
+
name='speedapi_lib',
|
|
5
|
+
version='0.1.1',
|
|
6
|
+
packages=find_packages(),
|
|
7
|
+
include_package_data=True,
|
|
8
|
+
install_requires=[
|
|
9
|
+
'requests',
|
|
10
|
+
'pydantic',
|
|
11
|
+
'pydantic-settings',
|
|
12
|
+
'bolt11',
|
|
13
|
+
],
|
|
14
|
+
entry_points={
|
|
15
|
+
'console_scripts': [
|
|
16
|
+
'speedapi_lib=speedapi_lib.main:main',
|
|
17
|
+
],
|
|
18
|
+
},
|
|
19
|
+
author='Furkan Köykıran',
|
|
20
|
+
author_email='furkankoykiran@gmail.com',
|
|
21
|
+
description='A Python library for interacting with Speed API and managing Lightning Network invoices',
|
|
22
|
+
long_description=open('README.md').read(),
|
|
23
|
+
long_description_content_type='text/markdown',
|
|
24
|
+
url='https://github.com/furkankoykiran/speedapi_lib',
|
|
25
|
+
classifiers=[
|
|
26
|
+
'Programming Language :: Python :: 3',
|
|
27
|
+
'License :: OSI Approved :: MIT License',
|
|
28
|
+
'Operating System :: OS Independent',
|
|
29
|
+
],
|
|
30
|
+
python_requires='>=3.7',
|
|
31
|
+
)
|
|
File without changes
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import requests
|
|
2
|
+
import base64
|
|
3
|
+
|
|
4
|
+
class SpeedAPIClient:
|
|
5
|
+
def __init__(self, secret_key: str, base_url: str):
|
|
6
|
+
self.secret_key = secret_key
|
|
7
|
+
self.base_url = base_url
|
|
8
|
+
self.base64_key = self._encode_secret_key(secret_key)
|
|
9
|
+
|
|
10
|
+
def _encode_secret_key(self, secret_key: str) -> str:
|
|
11
|
+
secret_key_bytes = f"{secret_key}:".encode("ascii")
|
|
12
|
+
return base64.b64encode(secret_key_bytes).decode("ascii")
|
|
13
|
+
|
|
14
|
+
def get_balance_sats(self) -> float:
|
|
15
|
+
url = f"{self.base_url}/balances"
|
|
16
|
+
headers = {
|
|
17
|
+
"accept": "application/json",
|
|
18
|
+
"authorization": f"Basic {self.base64_key}",
|
|
19
|
+
}
|
|
20
|
+
response = requests.get(url, headers=headers)
|
|
21
|
+
data = response.json()
|
|
22
|
+
balance = next(item["amount"] for item in data["available"] if item["target_currency"] == "SATS")
|
|
23
|
+
return balance
|
|
24
|
+
|
|
25
|
+
def pay_invoice(self, invoice: str) -> dict:
|
|
26
|
+
url = f"{self.base_url}/send"
|
|
27
|
+
headers = {
|
|
28
|
+
"accept": "application/json",
|
|
29
|
+
"authorization": f"Basic {self.base64_key}",
|
|
30
|
+
"content-type": "application/json"
|
|
31
|
+
}
|
|
32
|
+
payload = {
|
|
33
|
+
"currency": "SATS",
|
|
34
|
+
"withdraw_method": "lightning",
|
|
35
|
+
"withdraw_request": f"{invoice}"
|
|
36
|
+
}
|
|
37
|
+
response = requests.post(url, headers=headers, json=payload)
|
|
38
|
+
return response.json()
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
from pydantic_settings import BaseSettings, SettingsConfigDict
|
|
2
|
+
from pydantic import Field
|
|
3
|
+
|
|
4
|
+
class AppConfig(BaseSettings):
|
|
5
|
+
# Speed API Variables
|
|
6
|
+
PUBLISHABLE_KEY: str = Field(..., env='SPEED_PUBLISHABLE_KEY')
|
|
7
|
+
SECRET_KEY: str = Field(..., env='SPEED_SECRET_KEY')
|
|
8
|
+
BASE_URL: str = Field(..., env='SPEED_BASE_URL')
|
|
9
|
+
|
|
10
|
+
# Settings for Config class
|
|
11
|
+
model_config = SettingsConfigDict(
|
|
12
|
+
env_file='.env',
|
|
13
|
+
env_file_encoding='utf-8'
|
|
14
|
+
)
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import bolt11
|
|
2
|
+
|
|
3
|
+
class Invoice:
|
|
4
|
+
def __init__(self, invoice: str):
|
|
5
|
+
self.invoice = invoice
|
|
6
|
+
self.decoded_invoice = self._decode_invoice()
|
|
7
|
+
|
|
8
|
+
def _decode_invoice(self):
|
|
9
|
+
return bolt11.decode(self.invoice)
|
|
10
|
+
|
|
11
|
+
def get_info(self) -> dict:
|
|
12
|
+
return {
|
|
13
|
+
"amount": self.decoded_invoice.amount_msat / 1000,
|
|
14
|
+
"timestamp": self.decoded_invoice.date,
|
|
15
|
+
"description": self.decoded_invoice.description,
|
|
16
|
+
"payment_hash": self.decoded_invoice.payment_hash,
|
|
17
|
+
"expiry": self.decoded_invoice.expiry
|
|
18
|
+
}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
Metadata-Version: 2.1
|
|
2
|
+
Name: speedapi_lib
|
|
3
|
+
Version: 0.1.1
|
|
4
|
+
Summary: A Python library for interacting with Speed API and managing Lightning Network invoices
|
|
5
|
+
Home-page: https://github.com/furkankoykiran/speedapi_lib
|
|
6
|
+
Author: Furkan Köykıran
|
|
7
|
+
Author-email: furkankoykiran@gmail.com
|
|
8
|
+
Classifier: Programming Language :: Python :: 3
|
|
9
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
10
|
+
Classifier: Operating System :: OS Independent
|
|
11
|
+
Requires-Python: >=3.7
|
|
12
|
+
Description-Content-Type: text/markdown
|
|
13
|
+
Requires-Dist: requests
|
|
14
|
+
Requires-Dist: pydantic
|
|
15
|
+
Requires-Dist: pydantic-settings
|
|
16
|
+
Requires-Dist: bolt11
|
|
17
|
+
|
|
18
|
+
# speedapi_lib
|
|
19
|
+
|
|
20
|
+
This is a Python library for interacting with the Speed API and managing Lightning Network invoices.
|
|
21
|
+
|
|
22
|
+
## Installation
|
|
23
|
+
|
|
24
|
+
You can install this library from your private GitHub repository:
|
|
25
|
+
|
|
26
|
+
```bash
|
|
27
|
+
pip install git+https://github.com/furkankoykiran/speedapi_lib.git@main
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
## Usage
|
|
31
|
+
|
|
32
|
+
```python
|
|
33
|
+
from speedapi_lib.api_client import SpeedAPIClient
|
|
34
|
+
from speedapi_lib.invoice import Invoice
|
|
35
|
+
from speedapi_lib.config import AppConfig
|
|
36
|
+
|
|
37
|
+
config = AppConfig()
|
|
38
|
+
|
|
39
|
+
client = SpeedAPIClient(secret_key=config.SECRET_KEY, base_url=config.BASE_URL)
|
|
40
|
+
balance = client.get_balance_sats()
|
|
41
|
+
print(f"Balance: {balance} SATS")
|
|
42
|
+
|
|
43
|
+
invoice_str = "your_invoice_here"
|
|
44
|
+
invoice = Invoice(invoice_str)
|
|
45
|
+
invoice_info = invoice.get_info()
|
|
46
|
+
print(invoice_info)
|
|
47
|
+
|
|
48
|
+
if balance >= invoice_info["amount"]:
|
|
49
|
+
payment = client.pay_invoice(invoice_str)
|
|
50
|
+
print(payment)
|
|
51
|
+
else:
|
|
52
|
+
print("Insufficient balance to pay invoice")
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
## License
|
|
56
|
+
|
|
57
|
+
This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
README.md
|
|
2
|
+
setup.py
|
|
3
|
+
speedapi_lib/__init__.py
|
|
4
|
+
speedapi_lib/api_client.py
|
|
5
|
+
speedapi_lib/config.py
|
|
6
|
+
speedapi_lib/invoice.py
|
|
7
|
+
speedapi_lib.egg-info/PKG-INFO
|
|
8
|
+
speedapi_lib.egg-info/SOURCES.txt
|
|
9
|
+
speedapi_lib.egg-info/dependency_links.txt
|
|
10
|
+
speedapi_lib.egg-info/entry_points.txt
|
|
11
|
+
speedapi_lib.egg-info/requires.txt
|
|
12
|
+
speedapi_lib.egg-info/top_level.txt
|
|
13
|
+
tests/__init__.py
|
|
14
|
+
tests/test_sample.py
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
File without changes
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import unittest
|
|
2
|
+
from speedapi_lib.api_client import SpeedAPIClient
|
|
3
|
+
|
|
4
|
+
class TestSpeedAPIClient(unittest.TestCase):
|
|
5
|
+
|
|
6
|
+
def test_get_balance_sats(self):
|
|
7
|
+
client = SpeedAPIClient(secret_key='your_secret_key', base_url='https://api.tryspeed.com')
|
|
8
|
+
balance = client.get_balance_sats()
|
|
9
|
+
self.assertIsInstance(balance, float)
|
|
10
|
+
|
|
11
|
+
if __name__ == '__main__':
|
|
12
|
+
unittest.main()
|