miscutils
Utilities for working with python projects.
Usage
logging_config
Default configuration for structlog.
Configure json logging at the INFO level:
from miscutils.logging_config import default_logging, LogFormat, Verbosity
default_logging(Verbosity.INFO, LogFormat.JSON)
Configure text logging at the DEBUG level:
from miscutils.logging_config import default_logging, LogFormat, Verbosity
default_logging(Verbosity.DEBUG, LogFormat.TEXT)
Configure text logging at the DEBUG level and filter out external loggers:
from miscutils.logging_config import default_logging, LogFormat, Verbosity
default_logging(Verbosity.DEBUG, LogFormat.TEXT, ["extern_logger_1"])
Log timing information for a function
Decorator to add timing information to the logs:
from miscutils.timer import timer
import structlog
@timer(structlog.get_logger(__name__))
def some_function():
pass
Create a namespace relative patch
Create namespace relative patches:
import some_package.sub_package.another_package as under_test
from miscutils.testing import relative_patch_maker
patch = relative_patch_maker(under_test.__name__)
class TestStuff:
#equivalent to @unittest.mock.patch("some_package.sub_package.another_package.something_to_patch")
@patch("something_to_patch")
def test_something(self, patched):
under_test.something()
patched.assert_called_once()
#equivalent to @unittest.mock.patch("some_package.sub_package.another_package.something_else_to_patch")
@patch("something_else_to_patch")
def test_something(self, patched):
under_test.something()
patched.assert_called_once()
Starlette Structlog middleware
Middleware for Starlette framework to log HTTP requests to structlog. Log entries will be made at the start and end of each request. Error requests (400s and 500s) will also be logged. Any calls that throw exceptions will be converted 500 responses.
from miscutils.middleware import StructlogRequestMiddleware
import structlog
app.add_middleware(StructlogRequestMiddleware(app, logger=structlog.get_logger(__name__)))
There are options to customize the logging:
import logging
import structlog
from miscutils.middleware import StructlogRequestMiddleware
app.add_middleware(StructlogRequestMiddleware(
app,
logger=structlog.get_logger(__name__),
log_level=logging.DEBUG, # Log at the DEBUG level.
ignored_status_codes={404}, # Do not log 404 errors.
))
Development Guide
This project uses poetry:
$ pip install poetry
$ cd to/project/root
$ poetry install
Testing
Testing is done via pytest.
$ poetry run pytest
Metadata
Release files for misc-utils-py 0.3.0
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 |
|---|---|---|---|---|
| misc-utils-py-0.3.0.tar.gz | 9.2 kB | Without provenance | Details for misc-utils-py-0.3.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| misc_utils_py-0.3.0-py3-none-any.whl | Python 3 | none | any | Details for misc_utils_py-0.3.0-py3-none-any.whl |
Total release size: 19.4 kB
Release files / misc-utils-py-0.3.0.tar.gz
| Download URL | misc-utils-py-0.3.0.tar.gz |
|---|---|
| Size | 9.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
887514753e2c18b96170c0db6c966ec70a8b979b763d6b18cbd193d03988791b
|
|
BLAKE2b-256 checksum How to use checksums |
3bbddc64bb64f6cce643561215f07da91c0f3b24fa330a272b3177559950201c
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.0.9 CPython/3.8.3 Linux/5.3.0-1031-azure
|
Release files / misc_utils_py-0.3.0-py3-none-any.whl
| Download URL | misc_utils_py-0.3.0-py3-none-any.whl |
|---|---|
| Size | 10.1 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
c96127ac54ec29c0cf1ed741c0e25ea1ec7ed0407660a7f3c877d0e7b82e518a
|
|
BLAKE2b-256 checksum How to use checksums |
0620741f79273ca9b679c6686e0a6935aa3ac7457e577849be8e37ed879bed9e
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.0.9 CPython/3.8.3 Linux/5.3.0-1031-azure
|
Security for misc-utils-py 0.3.0
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.