mpacklog.py
Stream dictionaries to files or over the network using MessagePack in Python.
Installation
From conda-forge
conda install -c conda-forge mpacklog
From PyPI
pip install mpacklog
Usage
Asynchronous API
Add messages to the log using the put function, have them written to file in the separate write coroutine.
import asyncio
import mpacklog
async def main():
logger = mpacklog.AsyncLogger("output.mpack")
await asyncio.gather(main_loop(logger), logger.write())
async def main_loop(logger):
for bar in range(1000):
await asyncio.sleep(1e-3)
await logger.put({"foo": bar, "something": "else"})
await logger.stop()
if __name__ == "__main__":
asyncio.run(main())
Synchronous API
The synchronous API is similar to the asynchronous API, except it doesn't provide a stop method and the put and write methods are blocking.
import mpacklog
logger = mpacklog.SyncLogger("output.mpack")
for bar in range(1000):
logger.put({"foo": bar, "something": "else"})
# Flush all messages to the file
logger.write()
Command-line
The mpacklog utility provides commands to manipulate .mpack files.
dump
The dump command writes down a log file to newline-delimited JSON:
mpacklog dump my_log.mpack
list
This commands lists all nested dictionary keys encountered in a log file. Nested keys are separated by slashes / in the output. For instance, if some dictionaries in my_log.mpack contain values at dict["foo"]["bar"] and dict["foo"]["cbs"], the command will produce:
$ mpacklog list my_log.mpack
- foo/bar
- foo/cbs
serve
The serve command watches a log file for updates and serves the last dictionary appended to it over the network. Its argument is either a log file or a directory containing log files. In the second case, the most recent log files in the directory is opened:
$ mpacklog serve /var/log/my_mpack_logs/
You can use mpackview to connect a live plot to the server, or develop your own tool (the server API is quite simple).
See also
- foxplot: explore and plot time-series data from MessagePack and line-delimited JSON files.
- jq: manipulate JSON series to add, remove or extend fields.
- moteus-gui: motor driver telemetry GUI from which
mpackviewwas derived - mpacklog.cpp: log dictionaries to MessagePack files in C++.
- rq: transform from/to MessagePack, JSON, YAML, TOML, etc. For instance
mpacklog dumpis equivalent torq -mJ < my_log.mpack.
Metadata
Release files for mpacklog 4.0.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| mpacklog-4.0.1.tar.gz | 31.5 kB | Without provenance | Details for mpacklog-4.0.1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| mpacklog-4.0.1-py3-none-any.whl | Python 3 | none | any | Details for mpacklog-4.0.1-py3-none-any.whl |
Total release size: 50.2 kB
Release files / mpacklog-4.0.1.tar.gz
| Download URL | mpacklog-4.0.1.tar.gz |
|---|---|
| Size | 31.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
bf8af84a193c4655ee33e4e41451811b69a0689acacda5e88f3adf837635e113
|
|
BLAKE2b-256 checksum How to use checksums |
351423e41d3f11f30f23664cad2314301340350b6e10475e61111c3216b65614
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
python-requests/2.31.0
|
Release files / mpacklog-4.0.1-py3-none-any.whl
| Download URL | mpacklog-4.0.1-py3-none-any.whl |
|---|---|
| Size | 18.6 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
07b2c1ffc225af3006ed3e6e7339f5221e618ba25c301b04ef78504c2a1331a5
|
|
BLAKE2b-256 checksum How to use checksums |
da25981aae6836ca0c23fce5942a73f726139864c1d974878c52c9b6996f1b1f
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
python-requests/2.31.0
|
Security for mpacklog 4.0.1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.