Skip to content

Commit 6d51e0c

Browse files
authored
Merge pull request #64 from RIPE-NCC/release-2.0.0
2.0.0 with new version of the AtlasStream class
2 parents fc9ea22 + c48fc90 commit 6d51e0c

8 files changed

Lines changed: 331 additions & 267 deletions

File tree

.github/workflows/python-package.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ jobs:
1616
strategy:
1717
fail-fast: false
1818
matrix:
19-
python-version: ["3.6", "3.7", "3.8", "3.9", "3.10"]
19+
python-version: ["3.7", "3.8", "3.9", "3.10"]
2020

2121
steps:
2222
- uses: actions/checkout@v2

CHANGES.rst

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,20 @@
11
Releases History
22
================
33

4+
2.0.0 (release 2023-01-20)
5+
--------------------------
6+
Changes:
7+
~~~~~~~~
8+
- The AtlasStream class has been updated to use the new WebSocket interface
9+
- AtlasStream objects can now be iterated as an alternative to using callbacks
10+
- There used to be both start_stream() and subscribe() methods which did the same thing,
11+
except that start_stream() had extra validation. This extra validation has been
12+
added to subscribe(), and start_stream() is now an alias to it.
13+
- bind_channel() was renamed to bind(), although it is maintained as an alias, and
14+
there is a corresponding unbind() to remove a callback
15+
- Deprecated event aliases were dropped, you have to use full event names like
16+
"atlas_result" and "atlas_metadata" when binding
17+
418
1.5.1 (release 2022-05-23)
519
--------------------------
620
Bug Fixes:

docs/use.rst

Lines changed: 19 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -271,14 +271,14 @@ Example:
271271
272272
Streaming API
273273
-------------
274-
Atlas supports getting results and other events through a stream to get them close to real time. The stream is implemented using WebSockets and the `Socket.IO`_ protocol.
274+
Atlas supports getting results and other events through a WebSocket stream to get them close to real time. The AtlasStream class provides an interface to this stream, and supports
275+
both callback-based and iterator-based access.
275276

276277
Measurement Results
277278
^^^^^^^^^^^^^^^^^^^
278-
Besides fetching results from main API it is possible to get results though streaming API. You have to use AtlasStream object and bind to "result" channel. You can start the a result stream by specifying at least the measurement ID in the stream parameters.
279-
More details on the available parameters of the stream can be found on the `streaming documentation`_.
279+
You have to create an AtlasStream object and subscribe to the "result" stream type. More details on the available parameters of the stream can be found on the `streaming documentation`_.
280280

281-
Example:
281+
Example using the callback-interface:
282282

283283
.. code:: python
284284
@@ -295,13 +295,13 @@ Example:
295295
atlas_stream.connect()
296296
297297
# Bind function we want to run with every result message received
298-
atlas_stream.bind_channel("atlas_result", on_result_response)
298+
atlas_stream.bind("atlas_result", on_result_response)
299299
300300
# Subscribe to new stream for 1001 measurement results
301301
stream_parameters = {"msm": 1001}
302-
atlas_stream.start_stream(stream_type="result", **stream_parameters)
302+
atlas_stream.subscribe(stream_type="result", **stream_parameters)
303303
304-
# Timeout all subscriptions after 5 secs. Leave seconds empty for no timeout.
304+
# Process incoming events for 5 seconds, calling the callback defined above.
305305
# Make sure you have this line after you start *all* your streams
306306
atlas_stream.timeout(seconds=5)
307307
@@ -311,33 +311,27 @@ Example:
311311
312312
Connection Events
313313
^^^^^^^^^^^^^^^^^
314-
Besides results, streaming API supports also probe's connect/disconnect events. Again you have to use AtlasStream object but this time you have to bind to "probe" channel.
315-
More info about additional parameters can be found on the `streaming documentation`_.
314+
Besides results, the streaming API also supports probe connect/disconnect events.
315+
Again you have to create an AtlasStream object, but this time you subscribe to the
316+
"probestatus" stream type. More info about additional parameters can be found on
317+
the `streaming documentation`_.
316318

317-
Example:
319+
Example using the iterator-interface:
318320

319321
.. code:: python
320322
321323
from ripe.atlas.cousteau import AtlasStream
322324
323-
def on_result_response(*args):
324-
"""
325-
Function that will be called every time we receive a new event.
326-
Args is a tuple, so you should use args[0] to access the real event.
327-
"""
328-
print(args[0])
329-
330325
atlas_stream = AtlasStream()
331326
atlas_stream.connect()
332327
333-
# Probe's connection status results
334-
atlas_stream.bind_channel("atlas_probe", on_result_response)
335328
stream_parameters = {"enrichProbes": True}
336-
atlas_stream.start_stream(stream_type="probestatus", **stream_parameters)
329+
atlas_stream.subscribe(stream_type="probestatus", **stream_parameters)
330+
331+
# Iterate over the incoming results for 5 seconds
332+
for event_name, payload in atlas_stream.iter(seconds=5):
333+
print(event_name, payload)
337334
338-
# Timeout all subscriptions after 5 secs. Leave seconds empty for no timeout.
339-
# Make sure you have this line after you start *all* your streams
340-
atlas_stream.timeout(seconds=5)
341335
# Shut down everything
342336
atlas_stream.disconnect()
343337
@@ -346,8 +340,8 @@ Example:
346340
.. _streaming documentation: https://atlas.ripe.net/docs/result-streaming/
347341

348342

349-
Using Sagan Library
350-
-------------------
343+
Using the Sagan Library
344+
-----------------------
351345
In case you need to do further processing with any of the results you can use our official RIPE Atlas results parsing library called `Sagan`_.
352346
An example of how to combine two libraries is the below:
353347

0 commit comments

Comments
 (0)