Skip to main content

Log dictionaries to file using the MessagePack serialization format.

Project description

mpacklog

Build Coverage PyPI version PyPI downloads

Log dictionaries to MessagePack files in Python.

Installation

$ 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

If you pip-installed mpacklog, you can use the mpacklog command to dump logs to JSON:

mpacklog dump my_log.mpack

Alternatively and more generally, two great tools to manipulate logs from the command line are:

  • rq: transform from/to MessagePack, JSON, YAML, TOML, ...
  • jq: manipulate JSON series to add, remove or extend fields

For instance, mpacklog dump is equivalent to:

rq -mJ < my_log.mpack

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

mpacklog-3.1.0.tar.gz (14.1 kB view details)

Uploaded Source

Built Distribution

mpacklog-3.1.0-py3-none-any.whl (17.5 kB view details)

Uploaded Python 3

File details

Details for the file mpacklog-3.1.0.tar.gz.

File metadata

  • Download URL: mpacklog-3.1.0.tar.gz
  • Upload date:
  • Size: 14.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: python-requests/2.25.1

File hashes

Hashes for mpacklog-3.1.0.tar.gz
Algorithm Hash digest
SHA256 8abccaf8f3c62ffd413f599e2adcaed5f50eee8db8c319cb47d1d7909c9965c9
MD5 e6327d5607e170b2c6a08de537113430
BLAKE2b-256 605655dcf719fff4adfb590448a352b165153e3571c86ee1e74c0296fe4550d1

See more details on using hashes here.

Provenance

File details

Details for the file mpacklog-3.1.0-py3-none-any.whl.

File metadata

  • Download URL: mpacklog-3.1.0-py3-none-any.whl
  • Upload date:
  • Size: 17.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: python-requests/2.25.1

File hashes

Hashes for mpacklog-3.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 dbfcb42ab79ecb61f8baf1a054ce50ea74aa35ba4fcbfbeeb6ee5ed7aa5f61e9
MD5 c793e02483cb485885816ecb6b268f32
BLAKE2b-256 bd8ff97fc68bbc6a4818bf62b947fb77fc5268c68d18d25e61d20554848c6ee2

See more details on using hashes here.

Provenance

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page