session-python 1.0.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.
- session_python-1.0.0/LICENSE +21 -0
- session_python-1.0.0/PKG-INFO +155 -0
- session_python-1.0.0/README.md +133 -0
- session_python-1.0.0/pyproject.toml +31 -0
- session_python-1.0.0/session_python/__init__.py +4 -0
- session_python-1.0.0/session_python/client.py +729 -0
- session_python-1.0.0/session_python/crypto.py +298 -0
- session_python-1.0.0/session_python/mnemonic.py +76 -0
- session_python-1.0.0/session_python/network.py +193 -0
- session_python-1.0.0/session_python/polling.py +222 -0
- session_python-1.0.0/session_python/protobuf/__init__.py +1 -0
- session_python-1.0.0/session_python/protobuf/signalservice_pb2.py +112 -0
- session_python-1.0.0/session_python.egg-info/PKG-INFO +155 -0
- session_python-1.0.0/session_python.egg-info/SOURCES.txt +16 -0
- session_python-1.0.0/session_python.egg-info/dependency_links.txt +1 -0
- session_python-1.0.0/session_python.egg-info/requires.txt +5 -0
- session_python-1.0.0/session_python.egg-info/top_level.txt +1 -0
- session_python-1.0.0/setup.cfg +4 -0
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Towux
|
|
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,155 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: session-python
|
|
3
|
+
Version: 1.0.0
|
|
4
|
+
Summary: A pure Python implementation of the Session Messenger protocol client
|
|
5
|
+
Author-email: Towux <towux@users.noreply.github.com>
|
|
6
|
+
Project-URL: Homepage, https://github.com/towux/session-python
|
|
7
|
+
Project-URL: Bug Tracker, https://github.com/towux/session-python/issues
|
|
8
|
+
Classifier: Programming Language :: Python :: 3
|
|
9
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
10
|
+
Classifier: Operating System :: OS Independent
|
|
11
|
+
Classifier: Topic :: Communications :: Chat
|
|
12
|
+
Classifier: Intended Audience :: Developers
|
|
13
|
+
Requires-Python: >=3.8
|
|
14
|
+
Description-Content-Type: text/markdown
|
|
15
|
+
License-File: LICENSE
|
|
16
|
+
Requires-Dist: pynacl>=1.5.0
|
|
17
|
+
Requires-Dist: cryptography>=41.0.0
|
|
18
|
+
Requires-Dist: protobuf>=4.21.0
|
|
19
|
+
Requires-Dist: requests>=2.31.0
|
|
20
|
+
Requires-Dist: pysocks>=1.7.1
|
|
21
|
+
Dynamic: license-file
|
|
22
|
+
|
|
23
|
+
# session-python
|
|
24
|
+
|
|
25
|
+
[](https://pypi.org/project/session-python/)
|
|
26
|
+
[](https://opensource.org/licenses/MIT)
|
|
27
|
+
|
|
28
|
+
A pure Python implementation of the **Session Messenger** programmatic client protocol.
|
|
29
|
+
|
|
30
|
+
This library is a 1-to-1 port of the official `@session.js` (Bun) client modules to Python, allowing you to build Session bots, send encrypted messages, upload/download attachments, handle read receipts, typing indicators, message reactions, and unsends natively in Python, **without** wrapping any Node/Bun subprocesses.
|
|
31
|
+
|
|
32
|
+
---
|
|
33
|
+
|
|
34
|
+
## 🚀 Features
|
|
35
|
+
|
|
36
|
+
* **Zero JS Subprocesses**: Natively implemented in Python using PyNaCl, Cryptography, and Protobuf.
|
|
37
|
+
* **Oxen Mnemonics**: Ported 13-word Electrum/Monero style mnemonic decoder & encoder (Oxen standard) with CRC32 checksums.
|
|
38
|
+
* **Session Protocol Encryption**: SealedBox encryption, sender identity signatures, envelope wrapping, and 160-byte block size padding.
|
|
39
|
+
* **Proxy Support**: SOCKS5 and HTTP proxy support out of the box (uses `socks5h://` to perform remote DNS resolution for high privacy).
|
|
40
|
+
* **Redundant Node Routing**: Swarm lookup and node rotation (automatically retries other nodes in the swarm if a connection fails).
|
|
41
|
+
* **In-Memory Swarm Cache**: Caches resolved swarms to reduce network calls and decrease message sending latency by up to 4x.
|
|
42
|
+
* **Attachments Support**: Encrypts (AES-CBC + HMAC-SHA256) and uploads/downloads attachments to the Session file server.
|
|
43
|
+
* **Typing Indicators**: Show or hide typing indicators (`show_typing_indicator`, `hide_typing_indicator`).
|
|
44
|
+
* **Message Reactions**: React to messages with emojis (`add_reaction`, `remove_reaction`).
|
|
45
|
+
* **Read Receipts**: Mark messages as read (`mark_messages_as_read`).
|
|
46
|
+
* **Message Deletion (Unsend)**: Delete messages locally and propagate deletion commands (`delete_message`, `delete_messages`).
|
|
47
|
+
* **SOGS Support**: Sign and send requests to SOGS (Open Groups) (`send_sogs_request`, `sign_sogs_request`).
|
|
48
|
+
* **Pythonic Interface**: Exposes context managers (`with Session() as s:`) and static generators (`Session.generate_mnemonic()`).
|
|
49
|
+
|
|
50
|
+
---
|
|
51
|
+
|
|
52
|
+
## 📦 Installation
|
|
53
|
+
|
|
54
|
+
To install `session-python` along with its dependencies:
|
|
55
|
+
|
|
56
|
+
```bash
|
|
57
|
+
pip install pynacl cryptography protobuf requests pysocks
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
---
|
|
61
|
+
|
|
62
|
+
## 🛠️ Quick Start
|
|
63
|
+
|
|
64
|
+
### 1. Basic Send Message
|
|
65
|
+
|
|
66
|
+
```python
|
|
67
|
+
from session_python import Session
|
|
68
|
+
|
|
69
|
+
# Initialize with SOCKS5 proxy
|
|
70
|
+
PROXY = "socks5h://user:pass@host:port"
|
|
71
|
+
RECIPIENT_ID = "059ce57868de2b93dc56e3bce3780db7a7aadc91d8e236f4a8f972f92e609ab609"
|
|
72
|
+
|
|
73
|
+
with Session(proxy=PROXY) as session:
|
|
74
|
+
# Set your account mnemonic or generate a new one
|
|
75
|
+
mnemonic = Session.generate_mnemonic()
|
|
76
|
+
print(f"Generated new mnemonic: {mnemonic}")
|
|
77
|
+
|
|
78
|
+
session.set_mnemonic(mnemonic, display_name="Python Bot")
|
|
79
|
+
print(f"Your Session ID: {session.get_session_id()}")
|
|
80
|
+
|
|
81
|
+
# Send a text message
|
|
82
|
+
result = session.send_message(to=RECIPIENT_ID, text="Hello from Python!")
|
|
83
|
+
print(f"Message Hash: {result['messageHash']}")
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
### 2. Polling for Messages
|
|
87
|
+
|
|
88
|
+
```python
|
|
89
|
+
from session_python import Session, Poller
|
|
90
|
+
|
|
91
|
+
with Session(proxy=PROXY) as session:
|
|
92
|
+
session.set_mnemonic("your 13 word mnemonic here...")
|
|
93
|
+
|
|
94
|
+
poller = Poller(session)
|
|
95
|
+
print("Listening for messages...")
|
|
96
|
+
|
|
97
|
+
while True:
|
|
98
|
+
messages = poller.poll()
|
|
99
|
+
for msg in messages:
|
|
100
|
+
if msg["type"] == "data":
|
|
101
|
+
print(f"Received from {msg['from']}: {msg['body']}")
|
|
102
|
+
time.sleep(5)
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
### 3. File Attachments
|
|
106
|
+
|
|
107
|
+
```python
|
|
108
|
+
with Session(proxy=PROXY) as session:
|
|
109
|
+
session.set_mnemonic(mnemonic)
|
|
110
|
+
|
|
111
|
+
# 1. Send file attachment
|
|
112
|
+
with open("photo.jpg", "rb") as f:
|
|
113
|
+
file_bytes = f.read()
|
|
114
|
+
|
|
115
|
+
attachments = [{
|
|
116
|
+
"data": file_bytes,
|
|
117
|
+
"name": "photo.jpg",
|
|
118
|
+
"content_type": "image/jpeg"
|
|
119
|
+
}]
|
|
120
|
+
session.send_message(to=RECIPIENT_ID, text="Here is a file!", attachments=attachments)
|
|
121
|
+
|
|
122
|
+
# 2. Download and decrypt attachment from a polled message pointer
|
|
123
|
+
# file_ptr is extracted from incoming messages: msg["attachments"][0]
|
|
124
|
+
decrypted_file = session.get_file(file_ptr)
|
|
125
|
+
with open("downloaded_photo.jpg", "wb") as f:
|
|
126
|
+
f.write(decrypted_file)
|
|
127
|
+
```
|
|
128
|
+
|
|
129
|
+
### 4. Advanced Chat Operations
|
|
130
|
+
|
|
131
|
+
```python
|
|
132
|
+
with Session(proxy=PROXY) as session:
|
|
133
|
+
session.set_mnemonic(mnemonic)
|
|
134
|
+
|
|
135
|
+
# Typing Indicators
|
|
136
|
+
session.show_typing_indicator(RECIPIENT_ID)
|
|
137
|
+
time.sleep(2)
|
|
138
|
+
session.hide_typing_indicator(RECIPIENT_ID)
|
|
139
|
+
|
|
140
|
+
# Message Reactions
|
|
141
|
+
session.add_reaction(message_timestamp=1783586415070, message_author=RECIPIENT_ID, emoji="🔥")
|
|
142
|
+
session.remove_reaction(message_timestamp=1783586415070, message_author=RECIPIENT_ID, emoji="🔥")
|
|
143
|
+
|
|
144
|
+
# Read Receipts
|
|
145
|
+
session.mark_messages_as_read(conversation=RECIPIENT_ID, timestamps=[1783586415070])
|
|
146
|
+
|
|
147
|
+
# Delete / Unsend Messages
|
|
148
|
+
session.delete_message(conversation=RECIPIENT_ID, timestamp=1783586415070, hash_val="IXFgLeoj...")
|
|
149
|
+
```
|
|
150
|
+
|
|
151
|
+
---
|
|
152
|
+
|
|
153
|
+
## ⚖️ License
|
|
154
|
+
|
|
155
|
+
This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.
|
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
# session-python
|
|
2
|
+
|
|
3
|
+
[](https://pypi.org/project/session-python/)
|
|
4
|
+
[](https://opensource.org/licenses/MIT)
|
|
5
|
+
|
|
6
|
+
A pure Python implementation of the **Session Messenger** programmatic client protocol.
|
|
7
|
+
|
|
8
|
+
This library is a 1-to-1 port of the official `@session.js` (Bun) client modules to Python, allowing you to build Session bots, send encrypted messages, upload/download attachments, handle read receipts, typing indicators, message reactions, and unsends natively in Python, **without** wrapping any Node/Bun subprocesses.
|
|
9
|
+
|
|
10
|
+
---
|
|
11
|
+
|
|
12
|
+
## 🚀 Features
|
|
13
|
+
|
|
14
|
+
* **Zero JS Subprocesses**: Natively implemented in Python using PyNaCl, Cryptography, and Protobuf.
|
|
15
|
+
* **Oxen Mnemonics**: Ported 13-word Electrum/Monero style mnemonic decoder & encoder (Oxen standard) with CRC32 checksums.
|
|
16
|
+
* **Session Protocol Encryption**: SealedBox encryption, sender identity signatures, envelope wrapping, and 160-byte block size padding.
|
|
17
|
+
* **Proxy Support**: SOCKS5 and HTTP proxy support out of the box (uses `socks5h://` to perform remote DNS resolution for high privacy).
|
|
18
|
+
* **Redundant Node Routing**: Swarm lookup and node rotation (automatically retries other nodes in the swarm if a connection fails).
|
|
19
|
+
* **In-Memory Swarm Cache**: Caches resolved swarms to reduce network calls and decrease message sending latency by up to 4x.
|
|
20
|
+
* **Attachments Support**: Encrypts (AES-CBC + HMAC-SHA256) and uploads/downloads attachments to the Session file server.
|
|
21
|
+
* **Typing Indicators**: Show or hide typing indicators (`show_typing_indicator`, `hide_typing_indicator`).
|
|
22
|
+
* **Message Reactions**: React to messages with emojis (`add_reaction`, `remove_reaction`).
|
|
23
|
+
* **Read Receipts**: Mark messages as read (`mark_messages_as_read`).
|
|
24
|
+
* **Message Deletion (Unsend)**: Delete messages locally and propagate deletion commands (`delete_message`, `delete_messages`).
|
|
25
|
+
* **SOGS Support**: Sign and send requests to SOGS (Open Groups) (`send_sogs_request`, `sign_sogs_request`).
|
|
26
|
+
* **Pythonic Interface**: Exposes context managers (`with Session() as s:`) and static generators (`Session.generate_mnemonic()`).
|
|
27
|
+
|
|
28
|
+
---
|
|
29
|
+
|
|
30
|
+
## 📦 Installation
|
|
31
|
+
|
|
32
|
+
To install `session-python` along with its dependencies:
|
|
33
|
+
|
|
34
|
+
```bash
|
|
35
|
+
pip install pynacl cryptography protobuf requests pysocks
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
---
|
|
39
|
+
|
|
40
|
+
## 🛠️ Quick Start
|
|
41
|
+
|
|
42
|
+
### 1. Basic Send Message
|
|
43
|
+
|
|
44
|
+
```python
|
|
45
|
+
from session_python import Session
|
|
46
|
+
|
|
47
|
+
# Initialize with SOCKS5 proxy
|
|
48
|
+
PROXY = "socks5h://user:pass@host:port"
|
|
49
|
+
RECIPIENT_ID = "059ce57868de2b93dc56e3bce3780db7a7aadc91d8e236f4a8f972f92e609ab609"
|
|
50
|
+
|
|
51
|
+
with Session(proxy=PROXY) as session:
|
|
52
|
+
# Set your account mnemonic or generate a new one
|
|
53
|
+
mnemonic = Session.generate_mnemonic()
|
|
54
|
+
print(f"Generated new mnemonic: {mnemonic}")
|
|
55
|
+
|
|
56
|
+
session.set_mnemonic(mnemonic, display_name="Python Bot")
|
|
57
|
+
print(f"Your Session ID: {session.get_session_id()}")
|
|
58
|
+
|
|
59
|
+
# Send a text message
|
|
60
|
+
result = session.send_message(to=RECIPIENT_ID, text="Hello from Python!")
|
|
61
|
+
print(f"Message Hash: {result['messageHash']}")
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
### 2. Polling for Messages
|
|
65
|
+
|
|
66
|
+
```python
|
|
67
|
+
from session_python import Session, Poller
|
|
68
|
+
|
|
69
|
+
with Session(proxy=PROXY) as session:
|
|
70
|
+
session.set_mnemonic("your 13 word mnemonic here...")
|
|
71
|
+
|
|
72
|
+
poller = Poller(session)
|
|
73
|
+
print("Listening for messages...")
|
|
74
|
+
|
|
75
|
+
while True:
|
|
76
|
+
messages = poller.poll()
|
|
77
|
+
for msg in messages:
|
|
78
|
+
if msg["type"] == "data":
|
|
79
|
+
print(f"Received from {msg['from']}: {msg['body']}")
|
|
80
|
+
time.sleep(5)
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
### 3. File Attachments
|
|
84
|
+
|
|
85
|
+
```python
|
|
86
|
+
with Session(proxy=PROXY) as session:
|
|
87
|
+
session.set_mnemonic(mnemonic)
|
|
88
|
+
|
|
89
|
+
# 1. Send file attachment
|
|
90
|
+
with open("photo.jpg", "rb") as f:
|
|
91
|
+
file_bytes = f.read()
|
|
92
|
+
|
|
93
|
+
attachments = [{
|
|
94
|
+
"data": file_bytes,
|
|
95
|
+
"name": "photo.jpg",
|
|
96
|
+
"content_type": "image/jpeg"
|
|
97
|
+
}]
|
|
98
|
+
session.send_message(to=RECIPIENT_ID, text="Here is a file!", attachments=attachments)
|
|
99
|
+
|
|
100
|
+
# 2. Download and decrypt attachment from a polled message pointer
|
|
101
|
+
# file_ptr is extracted from incoming messages: msg["attachments"][0]
|
|
102
|
+
decrypted_file = session.get_file(file_ptr)
|
|
103
|
+
with open("downloaded_photo.jpg", "wb") as f:
|
|
104
|
+
f.write(decrypted_file)
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
### 4. Advanced Chat Operations
|
|
108
|
+
|
|
109
|
+
```python
|
|
110
|
+
with Session(proxy=PROXY) as session:
|
|
111
|
+
session.set_mnemonic(mnemonic)
|
|
112
|
+
|
|
113
|
+
# Typing Indicators
|
|
114
|
+
session.show_typing_indicator(RECIPIENT_ID)
|
|
115
|
+
time.sleep(2)
|
|
116
|
+
session.hide_typing_indicator(RECIPIENT_ID)
|
|
117
|
+
|
|
118
|
+
# Message Reactions
|
|
119
|
+
session.add_reaction(message_timestamp=1783586415070, message_author=RECIPIENT_ID, emoji="🔥")
|
|
120
|
+
session.remove_reaction(message_timestamp=1783586415070, message_author=RECIPIENT_ID, emoji="🔥")
|
|
121
|
+
|
|
122
|
+
# Read Receipts
|
|
123
|
+
session.mark_messages_as_read(conversation=RECIPIENT_ID, timestamps=[1783586415070])
|
|
124
|
+
|
|
125
|
+
# Delete / Unsend Messages
|
|
126
|
+
session.delete_message(conversation=RECIPIENT_ID, timestamp=1783586415070, hash_val="IXFgLeoj...")
|
|
127
|
+
```
|
|
128
|
+
|
|
129
|
+
---
|
|
130
|
+
|
|
131
|
+
## ⚖️ License
|
|
132
|
+
|
|
133
|
+
This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["setuptools>=61.0.0", "wheel"]
|
|
3
|
+
build-backend = "setuptools.build_meta"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "session-python"
|
|
7
|
+
version = "1.0.0"
|
|
8
|
+
description = "A pure Python implementation of the Session Messenger protocol client"
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
authors = [
|
|
11
|
+
{ name = "Towux", email = "towux@users.noreply.github.com" }
|
|
12
|
+
]
|
|
13
|
+
classifiers = [
|
|
14
|
+
"Programming Language :: Python :: 3",
|
|
15
|
+
"License :: OSI Approved :: MIT License",
|
|
16
|
+
"Operating System :: OS Independent",
|
|
17
|
+
"Topic :: Communications :: Chat",
|
|
18
|
+
"Intended Audience :: Developers"
|
|
19
|
+
]
|
|
20
|
+
requires-python = ">=3.8"
|
|
21
|
+
dependencies = [
|
|
22
|
+
"pynacl>=1.5.0",
|
|
23
|
+
"cryptography>=41.0.0",
|
|
24
|
+
"protobuf>=4.21.0",
|
|
25
|
+
"requests>=2.31.0",
|
|
26
|
+
"pysocks>=1.7.1"
|
|
27
|
+
]
|
|
28
|
+
|
|
29
|
+
[project.urls]
|
|
30
|
+
"Homepage" = "https://github.com/towux/session-python"
|
|
31
|
+
"Bug Tracker" = "https://github.com/towux/session-python/issues"
|