pycoinos 0.1.0__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.
pycoinos-0.1.0/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Gaelincho
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,47 @@
1
+ Metadata-Version: 2.4
2
+ Name: pycoinos
3
+ Version: 0.1.0
4
+ Summary: A python helper for the coinos API
5
+ Author-email: Gaelincho <g43l@proton.me>
6
+ License-Expression: MIT
7
+ Project-URL: homepage, https://github.com/Gaelincho/pycoinos
8
+ Requires-Python: >=3.13
9
+ Description-Content-Type: text/markdown
10
+ License-File: LICENSE
11
+ Requires-Dist: requests>=2.33.1
12
+ Dynamic: license-file
13
+
14
+ # pycoinos
15
+
16
+ This package serves as a python toolkit for interacting with the [Coinos API](https://coinos.io/docs).
17
+
18
+ ## Usage
19
+
20
+ The main entry point for the package is the `Client` class. This class provides methods for interacting with the Coinos API.
21
+
22
+ ```python
23
+ from pycoinos import Client
24
+
25
+ client = Client("ey...") # your coinos token
26
+ ```
27
+
28
+ The `Client` class has the following methods:
29
+
30
+ - `me()`: Get your account details and balance.
31
+ - `post_invoice()`: Create an invoice (lightning) or address (bitcoin).
32
+ - `get_invoice()`: Fetch an invoice by passing a bitcoin address or lightning payment hash.
33
+ - `post_payment()`: Send a lightning payment.
34
+ - `bitcoin_payment()`: Send a bitcoin payment.
35
+ - `send()`: Send an internal payment to another coinos user.
36
+ - `get_payments()`: Get all payments sent or received by the current user.
37
+ - `set_token()`: Update the token for the client.
38
+
39
+ ## Changelog
40
+
41
+ - v0.1.0: Initial release
42
+
43
+ ## License
44
+
45
+ Copyright (c) 2026 Gaelincho
46
+
47
+ The pycoinos package is distributed under the [MIT License](./LICENSE).
@@ -0,0 +1,34 @@
1
+ # pycoinos
2
+
3
+ This package serves as a python toolkit for interacting with the [Coinos API](https://coinos.io/docs).
4
+
5
+ ## Usage
6
+
7
+ The main entry point for the package is the `Client` class. This class provides methods for interacting with the Coinos API.
8
+
9
+ ```python
10
+ from pycoinos import Client
11
+
12
+ client = Client("ey...") # your coinos token
13
+ ```
14
+
15
+ The `Client` class has the following methods:
16
+
17
+ - `me()`: Get your account details and balance.
18
+ - `post_invoice()`: Create an invoice (lightning) or address (bitcoin).
19
+ - `get_invoice()`: Fetch an invoice by passing a bitcoin address or lightning payment hash.
20
+ - `post_payment()`: Send a lightning payment.
21
+ - `bitcoin_payment()`: Send a bitcoin payment.
22
+ - `send()`: Send an internal payment to another coinos user.
23
+ - `get_payments()`: Get all payments sent or received by the current user.
24
+ - `set_token()`: Update the token for the client.
25
+
26
+ ## Changelog
27
+
28
+ - v0.1.0: Initial release
29
+
30
+ ## License
31
+
32
+ Copyright (c) 2026 Gaelincho
33
+
34
+ The pycoinos package is distributed under the [MIT License](./LICENSE).
@@ -0,0 +1,20 @@
1
+ [project]
2
+ name = "pycoinos"
3
+ version = "0.1.0"
4
+ description = "A python helper for the coinos API"
5
+ readme = "README.md"
6
+ authors = [{ name = "Gaelincho", email = "g43l@proton.me" }]
7
+ license = "MIT"
8
+ license-files = ["LICENSE"]
9
+ requires-python = ">=3.13"
10
+ dependencies = ["requests>=2.33.1"]
11
+
12
+ [project.scripts]
13
+ pycoinos = "pycoinos:main"
14
+
15
+ [build-system]
16
+ requires = ["setuptools>=61"]
17
+ build-backend = "setuptools.build_meta"
18
+
19
+ [project.urls]
20
+ homepage = "https://github.com/Gaelincho/pycoinos"
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+
@@ -0,0 +1,4 @@
1
+ from .client import Client
2
+
3
+ __all__ = ["Client"]
4
+ __version__ = "0.1.0"
@@ -0,0 +1,103 @@
1
+ import warnings
2
+ from dataclasses import dataclass
3
+ from typing import Any
4
+
5
+ from .constants import TYPES
6
+
7
+
8
+ class SecretStr:
9
+ def __init__(self, value: str):
10
+ self.__value = value
11
+
12
+ def getsecret(self):
13
+ return self.__value
14
+
15
+ def __str__(self):
16
+ warnings.warn("You can access the secret value with `getsecret()`", UserWarning)
17
+ return "*" * len(self.__value)
18
+
19
+ def __repr__(self):
20
+ return str(self)
21
+
22
+ def __eq__(self, other):
23
+ return self.__value == other
24
+
25
+ def __hash__(self):
26
+ return hash(self.__value)
27
+
28
+ def __len__(self):
29
+ return len(self.__value)
30
+
31
+ def __bool__(self):
32
+ return bool(self.__value)
33
+
34
+
35
+ @dataclass
36
+ class BaseUser:
37
+ currency: str
38
+ id: str
39
+ npub: str
40
+ picture: str
41
+ pubkey: str
42
+ username: str
43
+
44
+
45
+ @dataclass
46
+ class User(BaseUser):
47
+ balance: float
48
+ currencies: list[str]
49
+ fiat: bool
50
+ locked: Any
51
+ locktime: int
52
+ nsec: SecretStr
53
+ prompt: bool
54
+
55
+
56
+ @dataclass
57
+ class BaseAddress:
58
+ aid: str
59
+ amount: float
60
+ created: int
61
+ currency: str
62
+ hash: str
63
+ id: str
64
+ items: list
65
+ own: bool
66
+ pending: float
67
+ rate: float
68
+ received: float
69
+ text: str
70
+ tip: Any
71
+ type: TYPES
72
+ uid: str
73
+ user: BaseUser | None
74
+
75
+
76
+ @dataclass
77
+ class Address(BaseAddress):
78
+ address_type: str
79
+
80
+
81
+ @dataclass
82
+ class Invoice(BaseAddress):
83
+ expiry: int
84
+ paymentHash: str
85
+ confirmed: bool | None
86
+ fee: float | None
87
+ ourfee: float | None
88
+ ref: str | None
89
+
90
+
91
+ @dataclass
92
+ class Payment(Address, Invoice):
93
+ iid: str
94
+ memo: str
95
+ hex: str
96
+
97
+
98
+ @dataclass
99
+ class Payments:
100
+ payments: list[Payment]
101
+ count: int
102
+ incoming: dict
103
+ outcoming: dict
@@ -0,0 +1,185 @@
1
+ import warnings
2
+
3
+ import requests as r
4
+
5
+ from .classes import Address, Invoice, Payments, SecretStr, User
6
+ from .constants import BASE_URL, TYPES
7
+
8
+
9
+ class Client:
10
+ def __init__(self, token=None):
11
+ self._session = r.Session()
12
+ self.__token = token
13
+
14
+ def set_token(self, token):
15
+ self.__token = token
16
+
17
+ def me(self):
18
+ """Get your account details and balance."""
19
+
20
+ user: dict = self._session.get(
21
+ f"{BASE_URL}/me",
22
+ headers={
23
+ "Authorization": f"Bearer {self.__token}",
24
+ "Content-Type": "application/json",
25
+ },
26
+ ).json()
27
+
28
+ try:
29
+ user["nsec"] = SecretStr(user["nsec"])
30
+ except KeyError:
31
+ pass
32
+
33
+ return User(**user)
34
+
35
+ def post_invoice(
36
+ self,
37
+ type: TYPES = "lightning",
38
+ fiat: bool = False,
39
+ amount: float = -1,
40
+ webhook: str = None,
41
+ secret: str = None,
42
+ ) -> Invoice | Address:
43
+ """Create an invoice.
44
+ Args:
45
+ type: bitcoin or lightning
46
+ fiat: whether the amount is denominated in satoshis or local currency
47
+ amount: amount to be paid
48
+ webhook: remote endpoint to call when the invoice is paid
49
+ secret: a secret value passed to the webhook to authenticate the request
50
+
51
+ Returns:
52
+ Invoice (lightning) or Address (bitcoin)
53
+ """
54
+
55
+ if amount == -1:
56
+ raise ValueError("amount is required")
57
+
58
+ r = self._session.post(
59
+ f"{BASE_URL}/invoice",
60
+ headers={
61
+ "Authorization": f"Bearer {self.__token}",
62
+ "Content-Type": "application/json",
63
+ },
64
+ json={
65
+ "invoice": {
66
+ "type": type,
67
+ "fiat": fiat,
68
+ "amount": amount,
69
+ "webhook": webhook,
70
+ "secret": secret,
71
+ }
72
+ },
73
+ ).json()
74
+
75
+ if r["type"] == "lightning":
76
+ return Invoice(**r)
77
+ if r["type"] == "bitcoin":
78
+ return Address(**r)
79
+
80
+ raise ValueError("unknown invoice type", r["type"], r)
81
+
82
+ def get_invoice(self, hash: str) -> Invoice | Address:
83
+ """Fetch an invoice by passing a bitcoin address or lightning payment hash."""
84
+
85
+ r = self._session.get(
86
+ f"{BASE_URL}/invoice/{hash}",
87
+ headers={
88
+ "Authorization": f"Bearer {self.__token}",
89
+ "Content-Type": "application/json",
90
+ },
91
+ ).json()
92
+
93
+ if r["type"] == "lightning":
94
+ return Invoice(**r)
95
+ if r["type"] == "bitcoin":
96
+ return Address(**r)
97
+
98
+ raise ValueError("unknown invoice type", r["type"], r)
99
+
100
+ def post_payment(self, payreq: str) -> Invoice:
101
+ """Send a lightning payment."""
102
+
103
+ r = self._session.post(
104
+ f"{BASE_URL}/payments",
105
+ headers={
106
+ "Authorization": f"Bearer {self.__token}",
107
+ "Content-Type": "application/json",
108
+ },
109
+ json={"payreq": payreq},
110
+ ).json()
111
+
112
+ if r["type"] == "lightning":
113
+ return Invoice(**r)
114
+ if r["type"] == "bitcoin":
115
+ raise NotImplementedError(
116
+ "bitcoin payments not supported with this endpoint"
117
+ )
118
+
119
+ raise ValueError("unknown invoice type", r["type"], r)
120
+
121
+ def send(self, amount: float, username: str) -> dict:
122
+ """Send an internal payment to another user."""
123
+
124
+ r = self._session.post(
125
+ f"{BASE_URL}/send",
126
+ headers={
127
+ "Authorization": f"Bearer {self.__token}",
128
+ "Content-Type": "application/json",
129
+ },
130
+ json={"amount": amount, "username": username},
131
+ )
132
+ return r.json()
133
+
134
+ def bitcoin_payment(self, amount: float, address: str) -> dict:
135
+ """Send a bitcoin payment. This function hasn't been tested."""
136
+
137
+ r = self._session.post(
138
+ f"{BASE_URL}/bitcoin/send",
139
+ headers={
140
+ "Authorization": f"Bearer {self.__token}",
141
+ "Content-Type": "application/json",
142
+ },
143
+ json={"amount": amount, "address": address},
144
+ )
145
+ warnings.warn(
146
+ "This function hasn't been tested. Use at your own risk", UserWarning
147
+ )
148
+ return r.json()
149
+
150
+ def get_payments(
151
+ self,
152
+ start: int | None = None,
153
+ end: int | None = None,
154
+ limit: int | None = None,
155
+ offset: int | None = None,
156
+ ) -> Payments:
157
+ """Get all payments sent or received by the current user
158
+
159
+ Args:
160
+ start: only payments after this unix time
161
+ end: only payments before this unix time
162
+ limit: limit to this integer number of results
163
+ offset: start limiting from this integer offset
164
+ """
165
+
166
+ params = {}
167
+ if start is not None:
168
+ params["start"] = start
169
+ if end is not None:
170
+ params["end"] = end
171
+ if limit is not None:
172
+ params["limit"] = limit
173
+ if offset is not None:
174
+ params["offset"] = offset
175
+
176
+ r = self._session.get(
177
+ f"{BASE_URL}/payments",
178
+ headers={
179
+ "Authorization": f"Bearer {self.__token}",
180
+ "Content-Type": "application/json",
181
+ },
182
+ params=params,
183
+ )
184
+
185
+ return Payments(**r.json())
@@ -0,0 +1,4 @@
1
+ from typing import Literal
2
+
3
+ BASE_URL = "https://coinos.io/api"
4
+ TYPES = Literal["lightning", "bitcoin"]
@@ -0,0 +1,47 @@
1
+ Metadata-Version: 2.4
2
+ Name: pycoinos
3
+ Version: 0.1.0
4
+ Summary: A python helper for the coinos API
5
+ Author-email: Gaelincho <g43l@proton.me>
6
+ License-Expression: MIT
7
+ Project-URL: homepage, https://github.com/Gaelincho/pycoinos
8
+ Requires-Python: >=3.13
9
+ Description-Content-Type: text/markdown
10
+ License-File: LICENSE
11
+ Requires-Dist: requests>=2.33.1
12
+ Dynamic: license-file
13
+
14
+ # pycoinos
15
+
16
+ This package serves as a python toolkit for interacting with the [Coinos API](https://coinos.io/docs).
17
+
18
+ ## Usage
19
+
20
+ The main entry point for the package is the `Client` class. This class provides methods for interacting with the Coinos API.
21
+
22
+ ```python
23
+ from pycoinos import Client
24
+
25
+ client = Client("ey...") # your coinos token
26
+ ```
27
+
28
+ The `Client` class has the following methods:
29
+
30
+ - `me()`: Get your account details and balance.
31
+ - `post_invoice()`: Create an invoice (lightning) or address (bitcoin).
32
+ - `get_invoice()`: Fetch an invoice by passing a bitcoin address or lightning payment hash.
33
+ - `post_payment()`: Send a lightning payment.
34
+ - `bitcoin_payment()`: Send a bitcoin payment.
35
+ - `send()`: Send an internal payment to another coinos user.
36
+ - `get_payments()`: Get all payments sent or received by the current user.
37
+ - `set_token()`: Update the token for the client.
38
+
39
+ ## Changelog
40
+
41
+ - v0.1.0: Initial release
42
+
43
+ ## License
44
+
45
+ Copyright (c) 2026 Gaelincho
46
+
47
+ The pycoinos package is distributed under the [MIT License](./LICENSE).
@@ -0,0 +1,13 @@
1
+ LICENSE
2
+ README.md
3
+ pyproject.toml
4
+ src/pycoinos/__init__.py
5
+ src/pycoinos/classes.py
6
+ src/pycoinos/client.py
7
+ src/pycoinos/constants.py
8
+ src/pycoinos.egg-info/PKG-INFO
9
+ src/pycoinos.egg-info/SOURCES.txt
10
+ src/pycoinos.egg-info/dependency_links.txt
11
+ src/pycoinos.egg-info/entry_points.txt
12
+ src/pycoinos.egg-info/requires.txt
13
+ src/pycoinos.egg-info/top_level.txt
@@ -0,0 +1,2 @@
1
+ [console_scripts]
2
+ pycoinos = pycoinos:main
@@ -0,0 +1 @@
1
+ requests>=2.33.1
@@ -0,0 +1 @@
1
+ pycoinos