Skip to main content
https://img.shields.io/badge/stdlib--only-yes-green.svg https://travis-ci.org/cjrh/aiodec.svg?branch=master https://coveralls.io/repos/github/cjrh/aiodec/badge.svg?branch=master https://img.shields.io/pypi/pyversions/aiodec.svg https://img.shields.io/github/tag/cjrh/aiodec.svg https://img.shields.io/badge/install-pip%20install%20aiodec-ff69b4.svg https://img.shields.io/pypi/v/aiodec.svg https://img.shields.io/badge/calver-YYYY.MM.MINOR-22bfda.svg

aiodec

Decorators for asyncio

astopwatch

The astopwatch decorator is used in the following way:

from aiodec import astopwatch

@astopwatch
async def blah(x, y):
    return x + y

What does it do? This simple decorator will emit logs with the following message:

INFO:aiodec:Time taken: 0.0003 seconds

Not terribly special. Yet. You can also customize the log message:

from aiodec import astopwatch

@astopwatch(message_template='Time cost was $time_ sec', fmt='%.1g')
async def blah(x, y):
    return x + y

This outputs log messages with the following message:

INFO:aiodec:Time cost was 3e-4 sec

Two things: first, the template parameter used for the time cost is called $time_; second, you can customize the formatting of the seconds value. However, it can also do something a lot more interesting: it can include parameters from the wrapped function in the message:

from aiodec import astopwatch

@astopwatch(message_template='x=$x y=$y | $time_ seconds')
async def blah(x, y=2):
    return x + y


loop.run_until_complete(blah(1))

This outputs log messages with the following message:

INFO:aiodec:x=1 y=2 | 0.0003 seconds

Magic! Note that positional args and keyword args and default values are all handled correctly.

As you saw earlier, in addition to the function parameters, the special $time_ parameter will also be available. The other extra fields are:

  • $name_, which contains the __name__ of the wrapped function, and

  • $qualname_, which contains the __qualname__ of the wrapped function.

These three template parameters have a trailing underscore, to avoid collisions with any parameter names.

Release files for aiodec 2018.7.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for aiodec 2018.7.1
File Size Uploaded
aiodec-2018.7.1.tar.gz 8.2 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for aiodec 2018.7.1
File Interpreter ABI Platform
aiodec-2018.7.1-py2.py3-none-any.whl Python 2, Python 3 none any Details

Total release size: 24.2 kB

Release files / aiodec-2018.7.1.tar.gz

Download URL aiodec-2018.7.1.tar.gz
Size 8.2 kB
Tags Source
SHA-256 checksum
How to use checksums
e1c6a0967f93357fd843e6eeae28bf5def4a116a2c60b9abe77084efb448099c
BLAKE2b-256 checksum
How to use checksums
a18c6dcdc0ca64c7dc825d8f7e67e35d6e78b1eb79583e4641a0ebb856c0cb34
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release files / aiodec-2018.7.1-py2.py3-none-any.whl

Download URL aiodec-2018.7.1-py2.py3-none-any.whl
Size 16.0 kB
Tags Python 2 Python 3
SHA-256 checksum
How to use checksums
0c61c90e98f93384ade391d8fb7fc1052ce81fa192c384089ffda041da78d461
BLAKE2b-256 checksum
How to use checksums
a7424bf02aaea332cfe59ba621becce3bdcd8ebe0c07c576186f57b5092e02f5
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release history Release notifications | RSS feed

This release

2018.7.1 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page