Name | mpacklog JSON |
Version |
4.0.1
JSON |
| download |
home_page | None |
Summary | Log dictionaries to file using the MessagePack serialization format. |
upload_time | 2024-12-04 18:59:21 |
maintainer | None |
docs_url | None |
author | None |
requires_python | >=3.8 |
license | None |
keywords |
messagepack
serialization
logging
|
VCS |
|
bugtrack_url |
|
requirements |
No requirements were recorded.
|
Travis-CI |
No Travis.
|
coveralls test coverage |
No coveralls.
|
# mpacklog.py
[![Build](https://img.shields.io/github/actions/workflow/status/stephane-caron/mpacklog.py/ci.yml?branch=main)](https://github.com/stephane-caron/mpacklog.py/actions)
[![Documentation](https://img.shields.io/github/actions/workflow/status/stephane-caron/mpacklog.py/docs.yml?branch=main&label=docs)](https://stephane-caron.github.io/mpacklog.py/)
[![Coverage](https://coveralls.io/repos/github/stephane-caron/mpacklog.py/badge.svg?branch=main)](https://coveralls.io/github/stephane-caron/mpacklog.py?branch=main)
[![Conda version](https://img.shields.io/conda/vn/conda-forge/mpacklog.svg)](https://anaconda.org/conda-forge/mpacklog)
[![PyPI version](https://img.shields.io/pypi/v/mpacklog)](https://pypi.org/project/mpacklog/)
Stream dictionaries to files or over the network using MessagePack in Python.
## Installation
### From conda-forge
```console
conda install -c conda-forge mpacklog
```
### From PyPI
```console
pip install mpacklog
```
## Usage
#### Asynchronous API
Add messages to the log using the [`put`](https://stephane-caron.github.io/mpacklog.py/api.html#mpacklog.async_logger.AsyncLogger.put) function, have them written to file in the separate [`write`](https://stephane-caron.github.io/mpacklog.py/api.html#mpacklog.async_logger.AsyncLogger.write) coroutine.
```python
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.
```python
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](https://jsonlines.org):
```console
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`](https://pypi.org/project/mpackview) to connect a live plot to the server, or develop your own tool (the server API is quite simple).
## See also
* [foxplot](https://github.com/stephane-caron/foxplot): explore and plot time-series data from MessagePack and line-delimited JSON files.
* [jq](https://github.com/stedolan/jq): manipulate JSON series to add, remove or extend fields.
* [moteus-gui](https://pypi.org/project/moteus-gui/): motor driver telemetry GUI from which ``mpackview`` was derived
* [mpacklog.cpp](https://github.com/upkie/mpacklog.cpp): log dictionaries to MessagePack files in C++.
* [rq](https://github.com/dflemstr/rq): transform from/to MessagePack, JSON, YAML, TOML, etc. For instance ``mpacklog dump`` is equivalent to ``rq -mJ < my_log.mpack``.
Raw data
{
"_id": null,
"home_page": null,
"name": "mpacklog",
"maintainer": null,
"docs_url": null,
"requires_python": ">=3.8",
"maintainer_email": "St\u00e9phane Caron <stephane.caron@normalesup.org>",
"keywords": "messagepack, serialization, logging",
"author": null,
"author_email": "St\u00e9phane Caron <stephane.caron@normalesup.org>",
"download_url": "https://files.pythonhosted.org/packages/35/14/23e41d3f11f30f23664cad2314301340350b6e10475e61111c3216b65614/mpacklog-4.0.1.tar.gz",
"platform": null,
"description": "# mpacklog.py\n\n[![Build](https://img.shields.io/github/actions/workflow/status/stephane-caron/mpacklog.py/ci.yml?branch=main)](https://github.com/stephane-caron/mpacklog.py/actions)\n[![Documentation](https://img.shields.io/github/actions/workflow/status/stephane-caron/mpacklog.py/docs.yml?branch=main&label=docs)](https://stephane-caron.github.io/mpacklog.py/)\n[![Coverage](https://coveralls.io/repos/github/stephane-caron/mpacklog.py/badge.svg?branch=main)](https://coveralls.io/github/stephane-caron/mpacklog.py?branch=main)\n[![Conda version](https://img.shields.io/conda/vn/conda-forge/mpacklog.svg)](https://anaconda.org/conda-forge/mpacklog)\n[![PyPI version](https://img.shields.io/pypi/v/mpacklog)](https://pypi.org/project/mpacklog/)\n\nStream dictionaries to files or over the network using MessagePack in Python.\n\n## Installation\n\n### From conda-forge\n\n```console\nconda install -c conda-forge mpacklog\n```\n\n### From PyPI\n\n```console\npip install mpacklog\n```\n\n## Usage\n\n#### Asynchronous API\n\nAdd messages to the log using the [`put`](https://stephane-caron.github.io/mpacklog.py/api.html#mpacklog.async_logger.AsyncLogger.put) function, have them written to file in the separate [`write`](https://stephane-caron.github.io/mpacklog.py/api.html#mpacklog.async_logger.AsyncLogger.write) coroutine.\n\n```python\nimport asyncio\nimport mpacklog\n\nasync def main():\n logger = mpacklog.AsyncLogger(\"output.mpack\")\n await asyncio.gather(main_loop(logger), logger.write())\n\nasync def main_loop(logger):\n for bar in range(1000):\n await asyncio.sleep(1e-3)\n await logger.put({\"foo\": bar, \"something\": \"else\"})\n await logger.stop()\n\nif __name__ == \"__main__\":\n asyncio.run(main())\n```\n\n#### Synchronous API\n\nThe synchronous API is similar to the asynchronous API, except it doesn't provide a ``stop`` method and the ``put`` and ``write`` methods are blocking.\n\n```python\nimport mpacklog\n\nlogger = mpacklog.SyncLogger(\"output.mpack\")\n\nfor bar in range(1000):\n logger.put({\"foo\": bar, \"something\": \"else\"})\n\n# Flush all messages to the file\nlogger.write()\n```\n\n## Command-line\n\nThe ``mpacklog`` utility provides commands to manipulate ``.mpack`` files.\n\n### ``dump``\n\nThe ``dump`` command writes down a log file to [newline-delimited JSON](https://jsonlines.org):\n\n```console\nmpacklog dump my_log.mpack\n```\n\n### ``list``\n\nThis 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:\n\n```\n$ mpacklog list my_log.mpack\n- foo/bar\n- foo/cbs\n```\n\n### ``serve``\n\nThe ``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:\n\n```\n$ mpacklog serve /var/log/my_mpack_logs/\n```\n\nYou can use [`mpackview`](https://pypi.org/project/mpackview) to connect a live plot to the server, or develop your own tool (the server API is quite simple).\n\n## See also\n\n* [foxplot](https://github.com/stephane-caron/foxplot): explore and plot time-series data from MessagePack and line-delimited JSON files.\n* [jq](https://github.com/stedolan/jq): manipulate JSON series to add, remove or extend fields.\n* [moteus-gui](https://pypi.org/project/moteus-gui/): motor driver telemetry GUI from which ``mpackview`` was derived\n* [mpacklog.cpp](https://github.com/upkie/mpacklog.cpp): log dictionaries to MessagePack files in C++.\n* [rq](https://github.com/dflemstr/rq): transform from/to MessagePack, JSON, YAML, TOML, etc. For instance ``mpacklog dump`` is equivalent to ``rq -mJ < my_log.mpack``.\n",
"bugtrack_url": null,
"license": null,
"summary": "Log dictionaries to file using the MessagePack serialization format.",
"version": "4.0.1",
"project_urls": {
"Changelog": "https://github.com/stephane-caron/mpacklog.py/blob/master/CHANGELOG.md",
"Homepage": "https://github.com/stephane-caron/mpacklog.py",
"Source": "https://github.com/stephane-caron/mpacklog.py",
"Tracker": "https://github.com/stephane-caron/mpacklog.py/issues"
},
"split_keywords": [
"messagepack",
" serialization",
" logging"
],
"urls": [
{
"comment_text": null,
"digests": {
"blake2b_256": "da25981aae6836ca0c23fce5942a73f726139864c1d974878c52c9b6996f1b1f",
"md5": "f545742802f68aca86a31e216c617d8e",
"sha256": "07b2c1ffc225af3006ed3e6e7339f5221e618ba25c301b04ef78504c2a1331a5"
},
"downloads": -1,
"filename": "mpacklog-4.0.1-py3-none-any.whl",
"has_sig": false,
"md5_digest": "f545742802f68aca86a31e216c617d8e",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.8",
"size": 18644,
"upload_time": "2024-12-04T18:59:18",
"upload_time_iso_8601": "2024-12-04T18:59:18.822252Z",
"url": "https://files.pythonhosted.org/packages/da/25/981aae6836ca0c23fce5942a73f726139864c1d974878c52c9b6996f1b1f/mpacklog-4.0.1-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": null,
"digests": {
"blake2b_256": "351423e41d3f11f30f23664cad2314301340350b6e10475e61111c3216b65614",
"md5": "867c15b4ddfdd5671968a10abb512025",
"sha256": "bf8af84a193c4655ee33e4e41451811b69a0689acacda5e88f3adf837635e113"
},
"downloads": -1,
"filename": "mpacklog-4.0.1.tar.gz",
"has_sig": false,
"md5_digest": "867c15b4ddfdd5671968a10abb512025",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.8",
"size": 31519,
"upload_time": "2024-12-04T18:59:21",
"upload_time_iso_8601": "2024-12-04T18:59:21.176713Z",
"url": "https://files.pythonhosted.org/packages/35/14/23e41d3f11f30f23664cad2314301340350b6e10475e61111c3216b65614/mpacklog-4.0.1.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-12-04 18:59:21",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "stephane-caron",
"github_project": "mpacklog.py",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"tox": true,
"lcname": "mpacklog"
}