Name | mpacklog JSON |
Version |
4.0.0
JSON |
| download |
home_page | None |
Summary | Log dictionaries to file using the MessagePack serialization format. |
upload_time | 2024-06-07 14:48:31 |
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/upkie/mpacklog.py/ci.yml?branch=main)](https://github.com/upkie/mpacklog.py/actions)
[![Documentation](https://img.shields.io/github/actions/workflow/status/upkie/mpacklog.py/docs.yml?branch=main&label=docs)](https://upkie.github.io/mpacklog.py/)
[![Coverage](https://coveralls.io/repos/github/upkie/mpacklog.py/badge.svg?branch=main)](https://coveralls.io/github/upkie/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://scaron.info/doc/mpacklog/classmpacklog_1_1mpacklog_1_1python_1_1logger_1_1Logger.html#aa0f928ac07280acd132627d8545a7e18) function, have them written to file in the separate [`write`](https://scaron.info/doc/mpacklog/classmpacklog_1_1mpacklog_1_1python_1_1logger_1_1Logger.html#acbea9c05c465423efc3f38a25ed699d2) 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.
* [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/6e/4e/e7e119f45279e7646a3369ae8a3719579ba5c5b1728fbf34abf83ecf6132/mpacklog-4.0.0.tar.gz",
"platform": null,
"description": "# mpacklog.py\n\n[![Build](https://img.shields.io/github/actions/workflow/status/upkie/mpacklog.py/ci.yml?branch=main)](https://github.com/upkie/mpacklog.py/actions)\n[![Documentation](https://img.shields.io/github/actions/workflow/status/upkie/mpacklog.py/docs.yml?branch=main&label=docs)](https://upkie.github.io/mpacklog.py/)\n[![Coverage](https://coveralls.io/repos/github/upkie/mpacklog.py/badge.svg?branch=main)](https://coveralls.io/github/upkie/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://scaron.info/doc/mpacklog/classmpacklog_1_1mpacklog_1_1python_1_1logger_1_1Logger.html#aa0f928ac07280acd132627d8545a7e18) function, have them written to file in the separate [`write`](https://scaron.info/doc/mpacklog/classmpacklog_1_1mpacklog_1_1python_1_1logger_1_1Logger.html#acbea9c05c465423efc3f38a25ed699d2) 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* [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.0",
"project_urls": {
"Changelog": "https://github.com/upkie/mpacklog.py/blob/master/CHANGELOG.md",
"Source": "https://github.com/upkie/mpacklog.py",
"Tracker": "https://github.com/upkie/mpacklog.py/issues"
},
"split_keywords": [
"messagepack",
" serialization",
" logging"
],
"urls": [
{
"comment_text": null,
"digests": {
"blake2b_256": "fbaf698a1a5578c428d573b40f475b474fa782536fb280007649cad7fc5cc94c",
"md5": "77b4b26c0bbdb6307de648beb865d477",
"sha256": "83f4d61fad2c4f986ff59a77bd354058add0df094a4581d0afcd017732b87aa3"
},
"downloads": -1,
"filename": "mpacklog-4.0.0-py3-none-any.whl",
"has_sig": false,
"md5_digest": "77b4b26c0bbdb6307de648beb865d477",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.8",
"size": 18654,
"upload_time": "2024-06-07T14:48:23",
"upload_time_iso_8601": "2024-06-07T14:48:23.348482Z",
"url": "https://files.pythonhosted.org/packages/fb/af/698a1a5578c428d573b40f475b474fa782536fb280007649cad7fc5cc94c/mpacklog-4.0.0-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": null,
"digests": {
"blake2b_256": "6e4ee7e119f45279e7646a3369ae8a3719579ba5c5b1728fbf34abf83ecf6132",
"md5": "d4e4bcd8386206f77e4e36009c24b4f7",
"sha256": "00e08f48a04222172480419b9d5be80b597818b87b07d8db152128387d8784d3"
},
"downloads": -1,
"filename": "mpacklog-4.0.0.tar.gz",
"has_sig": false,
"md5_digest": "d4e4bcd8386206f77e4e36009c24b4f7",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.8",
"size": 30741,
"upload_time": "2024-06-07T14:48:31",
"upload_time_iso_8601": "2024-06-07T14:48:31.891373Z",
"url": "https://files.pythonhosted.org/packages/6e/4e/e7e119f45279e7646a3369ae8a3719579ba5c5b1728fbf34abf83ecf6132/mpacklog-4.0.0.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-06-07 14:48:31",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "upkie",
"github_project": "mpacklog.py",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"tox": true,
"lcname": "mpacklog"
}