1322-python 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.
Files changed (37) hide show
  1. 1322_python-0.1.0/.env.example +26 -0
  2. 1322_python-0.1.0/.gitignore +14 -0
  3. 1322_python-0.1.0/LICENSE +21 -0
  4. 1322_python-0.1.0/PKG-INFO +273 -0
  5. 1322_python-0.1.0/README.md +239 -0
  6. 1322_python-0.1.0/examples/binance_example.py +38 -0
  7. 1322_python-0.1.0/examples/instagram_example.py +36 -0
  8. 1322_python-0.1.0/examples/news_example.py +36 -0
  9. 1322_python-0.1.0/examples/truth_example.py +40 -0
  10. 1322_python-0.1.0/examples/x_example.py +43 -0
  11. 1322_python-0.1.0/examples/youtube_example.py +37 -0
  12. 1322_python-0.1.0/pyproject.toml +60 -0
  13. 1322_python-0.1.0/scripts/smoke_test.py +173 -0
  14. 1322_python-0.1.0/src/client1322/__init__.py +48 -0
  15. 1322_python-0.1.0/src/client1322/_backoff.py +76 -0
  16. 1322_python-0.1.0/src/client1322/_merge.py +199 -0
  17. 1322_python-0.1.0/src/client1322/client.py +114 -0
  18. 1322_python-0.1.0/src/client1322/exceptions.py +40 -0
  19. 1322_python-0.1.0/src/client1322/platforms/__init__.py +1 -0
  20. 1322_python-0.1.0/src/client1322/platforms/_base.py +191 -0
  21. 1322_python-0.1.0/src/client1322/platforms/binance.py +219 -0
  22. 1322_python-0.1.0/src/client1322/platforms/instagram.py +146 -0
  23. 1322_python-0.1.0/src/client1322/platforms/news.py +150 -0
  24. 1322_python-0.1.0/src/client1322/platforms/truth.py +189 -0
  25. 1322_python-0.1.0/src/client1322/platforms/x.py +577 -0
  26. 1322_python-0.1.0/src/client1322/platforms/youtube.py +155 -0
  27. 1322_python-0.1.0/src/client1322/py.typed +0 -0
  28. 1322_python-0.1.0/tests/_fakes.py +112 -0
  29. 1322_python-0.1.0/tests/test_backoff.py +54 -0
  30. 1322_python-0.1.0/tests/test_client_stream.py +182 -0
  31. 1322_python-0.1.0/tests/test_merge_x.py +189 -0
  32. 1322_python-0.1.0/tests/test_parse_binance.py +85 -0
  33. 1322_python-0.1.0/tests/test_parse_instagram.py +137 -0
  34. 1322_python-0.1.0/tests/test_parse_news.py +71 -0
  35. 1322_python-0.1.0/tests/test_parse_truth.py +149 -0
  36. 1322_python-0.1.0/tests/test_parse_x.py +186 -0
  37. 1322_python-0.1.0/tests/test_parse_youtube.py +81 -0
@@ -0,0 +1,26 @@
1
+ # Copy this file to .env and fill in real values. Never commit .env.
2
+ #
3
+ # Each 1322 platform issues its own API key from your dashboard at
4
+ # https://1322.io. You only need the keys for the platform(s) you use.
5
+
6
+ # X / Twitter (Normal or Ultimate tier key)
7
+ X_API_KEY=YOUR_API_KEY_HERE
8
+
9
+ # Truth Social — REST key, plus the WS path/key shown in your dashboard config
10
+ TRUTH_API_KEY=YOUR_API_KEY_HERE
11
+ TRUTH_WS_PATH=YOUR_WS_PATH_HERE
12
+ TRUTH_WS_KEY=YOUR_WS_KEY_HERE
13
+
14
+ # Instagram (REST + WebSocket share the same key)
15
+ INSTAGRAM_API_KEY=YOUR_API_KEY_HERE
16
+
17
+ # News — REST key; ws_path/ws_key are fetched automatically from /v1/dashboard
18
+ NEWS_API_KEY=YOUR_API_KEY_HERE
19
+
20
+ # Binance Square — REST key; ws_path/ws_key are fetched automatically from /v1/dashboard
21
+ BINANCE_API_KEY=YOUR_API_KEY_HERE
22
+
23
+ # YouTube — API key plus the full WebSocket URL from your dashboard config
24
+ # (1322's public docs do not publish a fixed YouTube WS path; see README)
25
+ YOUTUBE_API_KEY=YOUR_API_KEY_HERE
26
+ YOUTUBE_WS_URL=YOUR_WS_URL_HERE
@@ -0,0 +1,14 @@
1
+ __pycache__/
2
+ *.py[cod]
3
+ *.egg-info/
4
+ .eggs/
5
+ build/
6
+ dist/
7
+ .pytest_cache/
8
+ .mypy_cache/
9
+ .ruff_cache/
10
+ .venv/
11
+ venv/
12
+ .env
13
+ .coverage
14
+ htmlcov/
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 SisoSol
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,273 @@
1
+ Metadata-Version: 2.4
2
+ Name: 1322-python
3
+ Version: 0.1.0
4
+ Summary: Unified async Python client for the 1322 real-time social monitoring API (X, Instagram, Truth Social, YouTube, Binance Square, News).
5
+ Project-URL: Homepage, https://1322.io
6
+ Project-URL: Documentation, https://1322.io/docs
7
+ Project-URL: Repository, https://github.com/SisoSol/1322-python
8
+ Project-URL: Issues, https://github.com/SisoSol/1322-python/issues
9
+ Author: SisoSol
10
+ License: MIT
11
+ License-File: LICENSE
12
+ Keywords: 1322,async,binance,instagram,realtime,social-media-monitoring,truth-social,twitter,websocket,x,youtube
13
+ Classifier: Development Status :: 4 - Beta
14
+ Classifier: Framework :: AsyncIO
15
+ Classifier: Intended Audience :: Developers
16
+ Classifier: License :: OSI Approved :: MIT License
17
+ Classifier: Operating System :: OS Independent
18
+ Classifier: Programming Language :: Python :: 3
19
+ Classifier: Programming Language :: Python :: 3 :: Only
20
+ Classifier: Programming Language :: Python :: 3.10
21
+ Classifier: Programming Language :: Python :: 3.11
22
+ Classifier: Programming Language :: Python :: 3.12
23
+ Classifier: Programming Language :: Python :: 3.13
24
+ Classifier: Topic :: Communications :: Chat
25
+ Classifier: Topic :: Internet :: WWW/HTTP :: Indexing/Search
26
+ Classifier: Topic :: Software Development :: Libraries :: Python Modules
27
+ Classifier: Typing :: Typed
28
+ Requires-Python: >=3.10
29
+ Requires-Dist: aiohttp>=3.9
30
+ Provides-Extra: dev
31
+ Requires-Dist: build>=1.0; extra == 'dev'
32
+ Requires-Dist: pytest>=8.0; extra == 'dev'
33
+ Description-Content-Type: text/markdown
34
+
35
+ # 1322-python
36
+
37
+ A unified async Python client for the [1322](https://1322.io) real-time social
38
+ monitoring API. 1322 tracks accounts on X (Twitter), Truth Social, Instagram,
39
+ YouTube, Binance Square, and 15+ news outlets, and delivers new posts,
40
+ updates, and deletions over WebSocket.
41
+
42
+ 1322 already publishes several single-platform example repos (see
43
+ [social-monitor-examples](https://github.com/SisoSol/social-monitor-examples)
44
+ and [binance-square-realtime](https://github.com/SisoSol/binance-square-realtime)).
45
+ This package is different: it's one installable, typed client covering all
46
+ six platforms behind a single consistent async shape, instead of copying a
47
+ connection script per platform.
48
+
49
+ ```python
50
+ from client1322 import Client
51
+
52
+ async with Client(platform="x", api_key="YOUR_API_KEY_HERE") as client:
53
+ async for event in client.stream():
54
+ print(event)
55
+ ```
56
+
57
+ ## Distribution name vs. import name
58
+
59
+ The PyPI distribution name is **`1322-python`** (Python package names on
60
+ PyPI may start with a digit; Python *module* names cannot). The importable
61
+ module is **`client1322`**. So you `pip install 1322-python` but
62
+ `import client1322` in code. Every example in this repo uses the real
63
+ import name.
64
+
65
+ ## Install
66
+
67
+ From GitHub (works today, no PyPI account needed):
68
+
69
+ ```bash
70
+ pip install git+https://github.com/SisoSol/1322-python
71
+ ```
72
+
73
+ From PyPI (once published -- see [Publishing](#publishing) below):
74
+
75
+ ```bash
76
+ pip install 1322-python
77
+ ```
78
+
79
+ Requires Python 3.10+.
80
+
81
+ ## Why one client instead of six scripts
82
+
83
+ 1322 documents six platforms, each with its own REST base URL, WebSocket
84
+ connection scheme, auth header, and event payload shape (see
85
+ [1322.io/docs](https://1322.io/docs) for the authoritative contract). This
86
+ package keeps that per-platform reality -- it does not invent a fake common
87
+ REST API that doesn't exist -- but gives you the same connection lifecycle,
88
+ reconnect behavior, and streaming interface everywhere:
89
+
90
+ - **One shape**: `async with Client(platform=..., api_key=...) as client:`
91
+ then `async for event in client.stream():`, for all six platforms.
92
+ - **Typed events**: every event is a `dataclass` with real field types
93
+ (`TypedDict`-typed nested payloads), not a loosely-typed `dict`. Full
94
+ `py.typed` support for IDEs and type checkers.
95
+ - **Auto-reconnect**: exponential backoff (1s, 2s, 4s, 8s, ... capped at
96
+ 30s), matching 1322's documented reconnection policy, implemented once
97
+ and shared by every platform adapter.
98
+ - **Additive tweet merge**: X tweets arrive across up to four progressive
99
+ stages (`tweet.mini.update` -> `tweet.update` -> `tweet.update.expanded`
100
+ -> `tweet.full`); `TweetMerger` implements 1322's documented merge rules
101
+ (longest text, unioned media, deepest reply/quote chain, highest metrics,
102
+ never overwrite a populated field with null) so you don't have to.
103
+ - **Thin REST helpers**: `track()` / `untrack()` / `list_tracked()` /
104
+ `health()` and friends, matching each platform's documented management
105
+ API exactly.
106
+
107
+ ## Platform coverage
108
+
109
+ | Platform | `platform=` | REST base | Connection details |
110
+ |---|---|---|---|
111
+ | X / Twitter | `"x"` (or `"twitter"`) | `api.1322.io` | fixed WS URL per tier (`normal`/`ultimate`) |
112
+ | Truth Social | `"truth"` | `truth.1322.io` | needs `ws_path`+`ws_key` from your dashboard |
113
+ | Instagram | `"instagram"` | `1322.io` | fixed WS URL, same key as REST |
114
+ | News | `"news"` | `newsfeed.1322.io` | `ws_path`/`ws_key` auto-fetched from `/v1/dashboard` |
115
+ | Binance Square | `"binance"` | `binance.1322.io` | `ws_path`/`ws_key` auto-fetched from `/v1/dashboard` |
116
+ | YouTube | `"youtube"` | -- | requires an explicit `ws_url` (see below) |
117
+
118
+ **About YouTube:** 1322's public docs describe the YouTube event payload
119
+ contract in full (upload / thumbnail upgrade / deletion) but, as of this
120
+ writing, do not publish a fixed WebSocket URL pattern or a customer-facing
121
+ REST tracked-account API for YouTube the way they do for the other five
122
+ platforms. Rather than guess at an undocumented endpoint, `YouTubeAdapter`
123
+ requires you to pass the exact WebSocket URL from your dashboard
124
+ configuration as `ws_url=`, and only implements event parsing -- no
125
+ `track()`/`untrack()`/`list_tracked()`, because 1322's docs don't define
126
+ them for this platform. Check [1322.io/docs](https://1322.io/docs) directly
127
+ if that changes.
128
+
129
+ ## Usage per platform
130
+
131
+ Runnable examples for all six platforms live in [`examples/`](examples/).
132
+ Each one reads its API key from an environment variable and does something
133
+ useful with the REST helpers plus the event stream. Quick summaries:
134
+
135
+ ### X / Twitter
136
+
137
+ ```python
138
+ from client1322 import Client, TweetMerger
139
+ from client1322.platforms.x import MiniTweetUpdate, TweetUpdate, TweetFull
140
+
141
+ merger = TweetMerger()
142
+
143
+ async with Client(platform="x", api_key="YOUR_API_KEY_HERE", tier="normal") as client:
144
+ async for event in client.stream():
145
+ if isinstance(event, (MiniTweetUpdate, TweetUpdate, TweetFull)):
146
+ merged = merger.merge(event.tweet) # dedup + additive merge by tweet id
147
+ print(merged["author"]["handle"], merged["body"]["text"])
148
+ ```
149
+
150
+ Also available: `client.list_tracked()`, `client.add_tracked("elonmusk")`,
151
+ `client.remove_tracked("elonmusk")`, `client.list_keys()`,
152
+ `client.get_tweet(tweet_id, full=True)`, `client.resolve_username("elonmusk")`.
153
+
154
+ ### Truth Social
155
+
156
+ ```python
157
+ async with Client(
158
+ platform="truth", api_key="YOUR_API_KEY_HERE",
159
+ ws_path="YOUR_WS_PATH_HERE", ws_key="YOUR_WS_KEY_HERE",
160
+ ) as client:
161
+ async for post in client.stream():
162
+ print(post.username, post.text)
163
+ ```
164
+
165
+ Also available: `client.track("realDonaldTrump")`, `client.untrack(...)`,
166
+ `client.list_tracked()`, `client.limits()`, `client.status()`, `client.health()`.
167
+
168
+ ### Instagram
169
+
170
+ ```python
171
+ async with Client(platform="instagram", api_key="YOUR_API_KEY_HERE") as client:
172
+ async for post in client.stream():
173
+ print(post.post_type, post.username, post.text)
174
+ ```
175
+
176
+ Also available: `client.track("username")`, `client.untrack(...)`,
177
+ `client.list_tracked()`, `client.limits()`, `client.health()`.
178
+
179
+ ### News
180
+
181
+ ```python
182
+ async with Client(platform="news", api_key="YOUR_API_KEY_HERE") as client:
183
+ async for article in client.stream():
184
+ print(article.feed, article.title, article.url)
185
+ ```
186
+
187
+ Also available: `client.dashboard()`, `client.subscribe("BBC News")`,
188
+ `client.unsubscribe(...)`.
189
+
190
+ ### Binance Square
191
+
192
+ ```python
193
+ from client1322.platforms.binance import BinancePinUpdateEvent, BinancePostEvent
194
+
195
+ async with Client(platform="binance", api_key="YOUR_API_KEY_HERE") as client:
196
+ async for event in client.stream():
197
+ if isinstance(event, BinancePostEvent):
198
+ print(event.post["username"], event.post.get("tendency"), event.post.get("text"))
199
+ elif isinstance(event, BinancePinUpdateEvent):
200
+ print("pin change:", event.pin["username"])
201
+ ```
202
+
203
+ Also available: `client.track("CZ_Binance")`, `client.untrack(...)`, `client.dashboard()`.
204
+
205
+ ### YouTube
206
+
207
+ ```python
208
+ from client1322.platforms.youtube import DeletionMessage, UploadMessage, UpgradeMessage
209
+
210
+ async with Client(
211
+ platform="youtube", api_key="YOUR_API_KEY_HERE", ws_url="YOUR_WS_URL_HERE"
212
+ ) as client:
213
+ async for event in client.stream():
214
+ if isinstance(event, UploadMessage):
215
+ print(event.channel["name"], event.video["title"])
216
+ elif isinstance(event, UpgradeMessage):
217
+ print("thumbnail upgraded:", event.upgrade["video_id"])
218
+ elif isinstance(event, DeletionMessage):
219
+ print("deleted:", event.video["id"])
220
+ ```
221
+
222
+ ## Auth and secrets
223
+
224
+ Each platform key comes from your [1322 dashboard](https://1322.io). Never
225
+ hardcode a key in source; read it from the environment instead. See
226
+ [`.env.example`](.env.example) for the full list of variables each platform
227
+ example expects.
228
+
229
+ ## Reconnection
230
+
231
+ `stream()` reconnects automatically on disconnect using 1322's documented
232
+ policy: exponential backoff starting at 1 second, doubling each attempt, and
233
+ capped at 30 seconds. No events are queued while disconnected -- this
234
+ matches 1322's documented server behavior, so a client that's offline will
235
+ simply miss whatever happened during that window, the same as any other
236
+ 1322 WebSocket client. Server-sent WebSocket pings are answered
237
+ automatically by the underlying `aiohttp` transport; you don't need to
238
+ handle that yourself. Pass `auto_reconnect=False` to `Client(...)` to
239
+ disable reconnection (`stream()` then returns after the first disconnect),
240
+ and `backoff_base=`/`backoff_cap=` to tune the delay curve.
241
+
242
+ ## Development
243
+
244
+ ```bash
245
+ git clone https://github.com/SisoSol/1322-python
246
+ cd 1322-python
247
+ python -m venv .venv && source .venv/bin/activate # or .venv\Scripts\activate on Windows
248
+ pip install -e ".[dev]"
249
+ pytest
250
+ ```
251
+
252
+ The test suite (`tests/`) covers backoff math, additive tweet merging, and
253
+ event parsing for all six platforms against payload shapes taken from
254
+ [1322.io/docs](https://1322.io/docs), plus an end-to-end `Client.stream()`
255
+ reconnect test driven against a fake `aiohttp` session (no real socket, no
256
+ API key needed). Every event-parsing fixture uses illustrative example
257
+ data, not measured production traffic.
258
+
259
+ ## Publishing
260
+
261
+ This repository is not published to PyPI yet. To publish it yourself:
262
+
263
+ ```bash
264
+ pip install build twine
265
+ python -m build
266
+ twine upload dist/*
267
+ ```
268
+
269
+ `twine upload` prompts for your PyPI credentials/API token interactively.
270
+
271
+ ## License
272
+
273
+ MIT, see [LICENSE](LICENSE).
@@ -0,0 +1,239 @@
1
+ # 1322-python
2
+
3
+ A unified async Python client for the [1322](https://1322.io) real-time social
4
+ monitoring API. 1322 tracks accounts on X (Twitter), Truth Social, Instagram,
5
+ YouTube, Binance Square, and 15+ news outlets, and delivers new posts,
6
+ updates, and deletions over WebSocket.
7
+
8
+ 1322 already publishes several single-platform example repos (see
9
+ [social-monitor-examples](https://github.com/SisoSol/social-monitor-examples)
10
+ and [binance-square-realtime](https://github.com/SisoSol/binance-square-realtime)).
11
+ This package is different: it's one installable, typed client covering all
12
+ six platforms behind a single consistent async shape, instead of copying a
13
+ connection script per platform.
14
+
15
+ ```python
16
+ from client1322 import Client
17
+
18
+ async with Client(platform="x", api_key="YOUR_API_KEY_HERE") as client:
19
+ async for event in client.stream():
20
+ print(event)
21
+ ```
22
+
23
+ ## Distribution name vs. import name
24
+
25
+ The PyPI distribution name is **`1322-python`** (Python package names on
26
+ PyPI may start with a digit; Python *module* names cannot). The importable
27
+ module is **`client1322`**. So you `pip install 1322-python` but
28
+ `import client1322` in code. Every example in this repo uses the real
29
+ import name.
30
+
31
+ ## Install
32
+
33
+ From GitHub (works today, no PyPI account needed):
34
+
35
+ ```bash
36
+ pip install git+https://github.com/SisoSol/1322-python
37
+ ```
38
+
39
+ From PyPI (once published -- see [Publishing](#publishing) below):
40
+
41
+ ```bash
42
+ pip install 1322-python
43
+ ```
44
+
45
+ Requires Python 3.10+.
46
+
47
+ ## Why one client instead of six scripts
48
+
49
+ 1322 documents six platforms, each with its own REST base URL, WebSocket
50
+ connection scheme, auth header, and event payload shape (see
51
+ [1322.io/docs](https://1322.io/docs) for the authoritative contract). This
52
+ package keeps that per-platform reality -- it does not invent a fake common
53
+ REST API that doesn't exist -- but gives you the same connection lifecycle,
54
+ reconnect behavior, and streaming interface everywhere:
55
+
56
+ - **One shape**: `async with Client(platform=..., api_key=...) as client:`
57
+ then `async for event in client.stream():`, for all six platforms.
58
+ - **Typed events**: every event is a `dataclass` with real field types
59
+ (`TypedDict`-typed nested payloads), not a loosely-typed `dict`. Full
60
+ `py.typed` support for IDEs and type checkers.
61
+ - **Auto-reconnect**: exponential backoff (1s, 2s, 4s, 8s, ... capped at
62
+ 30s), matching 1322's documented reconnection policy, implemented once
63
+ and shared by every platform adapter.
64
+ - **Additive tweet merge**: X tweets arrive across up to four progressive
65
+ stages (`tweet.mini.update` -> `tweet.update` -> `tweet.update.expanded`
66
+ -> `tweet.full`); `TweetMerger` implements 1322's documented merge rules
67
+ (longest text, unioned media, deepest reply/quote chain, highest metrics,
68
+ never overwrite a populated field with null) so you don't have to.
69
+ - **Thin REST helpers**: `track()` / `untrack()` / `list_tracked()` /
70
+ `health()` and friends, matching each platform's documented management
71
+ API exactly.
72
+
73
+ ## Platform coverage
74
+
75
+ | Platform | `platform=` | REST base | Connection details |
76
+ |---|---|---|---|
77
+ | X / Twitter | `"x"` (or `"twitter"`) | `api.1322.io` | fixed WS URL per tier (`normal`/`ultimate`) |
78
+ | Truth Social | `"truth"` | `truth.1322.io` | needs `ws_path`+`ws_key` from your dashboard |
79
+ | Instagram | `"instagram"` | `1322.io` | fixed WS URL, same key as REST |
80
+ | News | `"news"` | `newsfeed.1322.io` | `ws_path`/`ws_key` auto-fetched from `/v1/dashboard` |
81
+ | Binance Square | `"binance"` | `binance.1322.io` | `ws_path`/`ws_key` auto-fetched from `/v1/dashboard` |
82
+ | YouTube | `"youtube"` | -- | requires an explicit `ws_url` (see below) |
83
+
84
+ **About YouTube:** 1322's public docs describe the YouTube event payload
85
+ contract in full (upload / thumbnail upgrade / deletion) but, as of this
86
+ writing, do not publish a fixed WebSocket URL pattern or a customer-facing
87
+ REST tracked-account API for YouTube the way they do for the other five
88
+ platforms. Rather than guess at an undocumented endpoint, `YouTubeAdapter`
89
+ requires you to pass the exact WebSocket URL from your dashboard
90
+ configuration as `ws_url=`, and only implements event parsing -- no
91
+ `track()`/`untrack()`/`list_tracked()`, because 1322's docs don't define
92
+ them for this platform. Check [1322.io/docs](https://1322.io/docs) directly
93
+ if that changes.
94
+
95
+ ## Usage per platform
96
+
97
+ Runnable examples for all six platforms live in [`examples/`](examples/).
98
+ Each one reads its API key from an environment variable and does something
99
+ useful with the REST helpers plus the event stream. Quick summaries:
100
+
101
+ ### X / Twitter
102
+
103
+ ```python
104
+ from client1322 import Client, TweetMerger
105
+ from client1322.platforms.x import MiniTweetUpdate, TweetUpdate, TweetFull
106
+
107
+ merger = TweetMerger()
108
+
109
+ async with Client(platform="x", api_key="YOUR_API_KEY_HERE", tier="normal") as client:
110
+ async for event in client.stream():
111
+ if isinstance(event, (MiniTweetUpdate, TweetUpdate, TweetFull)):
112
+ merged = merger.merge(event.tweet) # dedup + additive merge by tweet id
113
+ print(merged["author"]["handle"], merged["body"]["text"])
114
+ ```
115
+
116
+ Also available: `client.list_tracked()`, `client.add_tracked("elonmusk")`,
117
+ `client.remove_tracked("elonmusk")`, `client.list_keys()`,
118
+ `client.get_tweet(tweet_id, full=True)`, `client.resolve_username("elonmusk")`.
119
+
120
+ ### Truth Social
121
+
122
+ ```python
123
+ async with Client(
124
+ platform="truth", api_key="YOUR_API_KEY_HERE",
125
+ ws_path="YOUR_WS_PATH_HERE", ws_key="YOUR_WS_KEY_HERE",
126
+ ) as client:
127
+ async for post in client.stream():
128
+ print(post.username, post.text)
129
+ ```
130
+
131
+ Also available: `client.track("realDonaldTrump")`, `client.untrack(...)`,
132
+ `client.list_tracked()`, `client.limits()`, `client.status()`, `client.health()`.
133
+
134
+ ### Instagram
135
+
136
+ ```python
137
+ async with Client(platform="instagram", api_key="YOUR_API_KEY_HERE") as client:
138
+ async for post in client.stream():
139
+ print(post.post_type, post.username, post.text)
140
+ ```
141
+
142
+ Also available: `client.track("username")`, `client.untrack(...)`,
143
+ `client.list_tracked()`, `client.limits()`, `client.health()`.
144
+
145
+ ### News
146
+
147
+ ```python
148
+ async with Client(platform="news", api_key="YOUR_API_KEY_HERE") as client:
149
+ async for article in client.stream():
150
+ print(article.feed, article.title, article.url)
151
+ ```
152
+
153
+ Also available: `client.dashboard()`, `client.subscribe("BBC News")`,
154
+ `client.unsubscribe(...)`.
155
+
156
+ ### Binance Square
157
+
158
+ ```python
159
+ from client1322.platforms.binance import BinancePinUpdateEvent, BinancePostEvent
160
+
161
+ async with Client(platform="binance", api_key="YOUR_API_KEY_HERE") as client:
162
+ async for event in client.stream():
163
+ if isinstance(event, BinancePostEvent):
164
+ print(event.post["username"], event.post.get("tendency"), event.post.get("text"))
165
+ elif isinstance(event, BinancePinUpdateEvent):
166
+ print("pin change:", event.pin["username"])
167
+ ```
168
+
169
+ Also available: `client.track("CZ_Binance")`, `client.untrack(...)`, `client.dashboard()`.
170
+
171
+ ### YouTube
172
+
173
+ ```python
174
+ from client1322.platforms.youtube import DeletionMessage, UploadMessage, UpgradeMessage
175
+
176
+ async with Client(
177
+ platform="youtube", api_key="YOUR_API_KEY_HERE", ws_url="YOUR_WS_URL_HERE"
178
+ ) as client:
179
+ async for event in client.stream():
180
+ if isinstance(event, UploadMessage):
181
+ print(event.channel["name"], event.video["title"])
182
+ elif isinstance(event, UpgradeMessage):
183
+ print("thumbnail upgraded:", event.upgrade["video_id"])
184
+ elif isinstance(event, DeletionMessage):
185
+ print("deleted:", event.video["id"])
186
+ ```
187
+
188
+ ## Auth and secrets
189
+
190
+ Each platform key comes from your [1322 dashboard](https://1322.io). Never
191
+ hardcode a key in source; read it from the environment instead. See
192
+ [`.env.example`](.env.example) for the full list of variables each platform
193
+ example expects.
194
+
195
+ ## Reconnection
196
+
197
+ `stream()` reconnects automatically on disconnect using 1322's documented
198
+ policy: exponential backoff starting at 1 second, doubling each attempt, and
199
+ capped at 30 seconds. No events are queued while disconnected -- this
200
+ matches 1322's documented server behavior, so a client that's offline will
201
+ simply miss whatever happened during that window, the same as any other
202
+ 1322 WebSocket client. Server-sent WebSocket pings are answered
203
+ automatically by the underlying `aiohttp` transport; you don't need to
204
+ handle that yourself. Pass `auto_reconnect=False` to `Client(...)` to
205
+ disable reconnection (`stream()` then returns after the first disconnect),
206
+ and `backoff_base=`/`backoff_cap=` to tune the delay curve.
207
+
208
+ ## Development
209
+
210
+ ```bash
211
+ git clone https://github.com/SisoSol/1322-python
212
+ cd 1322-python
213
+ python -m venv .venv && source .venv/bin/activate # or .venv\Scripts\activate on Windows
214
+ pip install -e ".[dev]"
215
+ pytest
216
+ ```
217
+
218
+ The test suite (`tests/`) covers backoff math, additive tweet merging, and
219
+ event parsing for all six platforms against payload shapes taken from
220
+ [1322.io/docs](https://1322.io/docs), plus an end-to-end `Client.stream()`
221
+ reconnect test driven against a fake `aiohttp` session (no real socket, no
222
+ API key needed). Every event-parsing fixture uses illustrative example
223
+ data, not measured production traffic.
224
+
225
+ ## Publishing
226
+
227
+ This repository is not published to PyPI yet. To publish it yourself:
228
+
229
+ ```bash
230
+ pip install build twine
231
+ python -m build
232
+ twine upload dist/*
233
+ ```
234
+
235
+ `twine upload` prompts for your PyPI credentials/API token interactively.
236
+
237
+ ## License
238
+
239
+ MIT, see [LICENSE](LICENSE).
@@ -0,0 +1,38 @@
1
+ """Binance Square: stream posts and pin changes for tracked creators.
2
+
3
+ Requires a Binance Square API key from https://1322.io. The WebSocket
4
+ path/key are fetched automatically from GET /v1/dashboard.
5
+
6
+ export BINANCE_API_KEY=YOUR_API_KEY_HERE
7
+ python binance_example.py
8
+ """
9
+
10
+ from __future__ import annotations
11
+
12
+ import asyncio
13
+ import os
14
+
15
+ from client1322 import Client
16
+ from client1322.platforms.binance import BinancePinUpdateEvent, BinancePostEvent
17
+
18
+ API_KEY = os.environ.get("BINANCE_API_KEY", "YOUR_API_KEY_HERE")
19
+
20
+
21
+ async def main() -> None:
22
+ async with Client(platform="binance", api_key=API_KEY) as client:
23
+ dash = await client.dashboard()
24
+ print(f"Tracking: {dash.get('tracked', [])}")
25
+
26
+ async for event in client.stream():
27
+ if isinstance(event, BinancePostEvent):
28
+ post = event.post
29
+ tendency = post.get("tendency") or "neutral"
30
+ pairs = ", ".join(post.get("coin_pairs") or [])
31
+ print(f"[post] @{post.get('username')} ({tendency}) {pairs}: {post.get('text', '')[:120]}")
32
+ elif isinstance(event, BinancePinUpdateEvent):
33
+ pin = event.pin
34
+ print(f"[pin change] @{pin.get('username')}: +{len(pin.get('added') or [])} -{len(pin.get('removed') or [])}")
35
+
36
+
37
+ if __name__ == "__main__":
38
+ asyncio.run(main())
@@ -0,0 +1,36 @@
1
+ """Instagram: stream posts, reels, stories, and carousels for tracked accounts.
2
+
3
+ Requires an Instagram API key from https://1322.io (the same key is used
4
+ for both REST and the WebSocket connection).
5
+
6
+ export INSTAGRAM_API_KEY=YOUR_API_KEY_HERE
7
+ python instagram_example.py
8
+ """
9
+
10
+ from __future__ import annotations
11
+
12
+ import asyncio
13
+ import os
14
+
15
+ from client1322 import Client
16
+
17
+ API_KEY = os.environ.get("INSTAGRAM_API_KEY", "YOUR_API_KEY_HERE")
18
+
19
+
20
+ async def main() -> None:
21
+ async with Client(platform="instagram", api_key=API_KEY) as client:
22
+ tracked = await client.list_tracked()
23
+ print(f"Tracking: {tracked.get('tracked', [])}")
24
+
25
+ async for post in client.stream():
26
+ tags = []
27
+ if post.is_collab:
28
+ tags.append(f"collab with {', '.join(post.collab_with or [])}")
29
+ if post.is_paid_partnership:
30
+ tags.append("paid partnership")
31
+ suffix = f" ({'; '.join(tags)})" if tags else ""
32
+ print(f"[{post.post_type}] @{post.username}: {post.text[:120]}{suffix}")
33
+
34
+
35
+ if __name__ == "__main__":
36
+ asyncio.run(main())
@@ -0,0 +1,36 @@
1
+ """News: stream articles from your subscribed feeds.
2
+
3
+ Requires a News API key from https://1322.io. The WebSocket path/key are
4
+ fetched automatically from GET /v1/dashboard -- no need to pass them.
5
+
6
+ export NEWS_API_KEY=YOUR_API_KEY_HERE
7
+ python news_example.py
8
+ """
9
+
10
+ from __future__ import annotations
11
+
12
+ import asyncio
13
+ import os
14
+
15
+ from client1322 import Client
16
+
17
+ API_KEY = os.environ.get("NEWS_API_KEY", "YOUR_API_KEY_HERE")
18
+
19
+
20
+ async def main() -> None:
21
+ async with Client(platform="news", api_key=API_KEY) as client:
22
+ dash = await client.dashboard()
23
+ print(f"Subscribed feeds: {dash.get('feeds', [])}")
24
+
25
+ # Add a feed if it isn't already subscribed. Feed names are listed at
26
+ # https://1322.io/docs under "Available Feeds".
27
+ if "BBC News" not in dash.get("feeds", []):
28
+ await client.subscribe("BBC News")
29
+
30
+ async for article in client.stream():
31
+ print(f"[{article.feed}] {article.title}")
32
+ print(f" {article.url}")
33
+
34
+
35
+ if __name__ == "__main__":
36
+ asyncio.run(main())