pylib Package
This is a py utils lib package, here are log and lots of methods. All methods you can see in file methods.py.
HTTP request metrics
HttpRequestMetricsMiddleware records the medlink_http_request_duration_seconds histogram
independently of HttpRequestLoggingMiddleware. Install each middleware separately, and start the
metrics-only listener from the application's lifespan:
from contextlib import asynccontextmanager
from fastapi import FastAPI
from pylib.gcp_logging import HttpRequestLoggingMiddleware
from pylib.http_metrics import HttpRequestMetricsMiddleware, start_http_metrics_server
@asynccontextmanager
async def lifespan(app: FastAPI):
metrics_server = start_http_metrics_server()
try:
yield
finally:
metrics_server.close()
app = FastAPI(lifespan=lifespan)
app.add_middleware(HttpRequestLoggingMiddleware)
app.add_middleware(HttpRequestMetricsMiddleware, service_tier="api")
The listener uses TCP port 9000 by default and serves only GET /metrics; application traffic,
Services, and probes can remain on port 8080. Set PROMETHEUS_MULTIPROC_DIR before importing
the module or starting workers. Give each pod a writable emptyDir shared by that pod's workers.
The listener returns 503 when this directory is not configured instead of exposing incomplete
worker-local data.
Labels use the Starlette route template (or /__unmatched__), a standard method or OTHER, status
class, service identity from MEDLINK_SERVICE_ID/SERVICE_ID/SERVICE_NAME, service_tier, and
APP_ENV (production normalizes to prod). Successful health probes and /metrics scrapes are
excluded; raw paths, query strings, request bodies, and identifiers are never label values. The
module uses Starlette ASGI types and the package requires Python >=3.10.
Usage
from pylib.log import log
log.debug('msg')
log.info('msg')
log.warning('msg')
log.error('msg')
log.critical('msg')
log.log('DEBUG', 'msg')
log.log('INFO', 'msg')
log.log('WARNING', 'msg')
log.log('ERROR', 'msg')
log.log('CRITICAL', 'msg', silence=True)
from pylib.methods import Methods
Methods.get_stack_funcs()
data_desensitived = Methods.mask_sensitive_data(dict_data)
Worker services can use the standard logging API with a logger name inferred from the calling module:
from pylib import logger
logger.info("worker_started")
Importing pylib.logger initializes GCP worker logging once for the current process. configure_worker_logging() remains available for explicit setup; repeated calls in the same process are ignored, while a forked child configures independently.
Metadata
Release files for medlink-pylib 0.0.19
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 | |
|---|---|---|---|---|
| medlink_pylib-0.0.19.tar.gz | 34.2 kB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| medlink_pylib-0.0.19-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 64.0 kB
Release files / medlink_pylib-0.0.19.tar.gz
| Download URL | medlink_pylib-0.0.19.tar.gz |
|---|---|
| Size | 34.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
fa401023f254d7ecd0108a3a6fb24411bc632d41f7e90703969b7f25ceacebc9
|
|
BLAKE2b-256 checksum How to use checksums |
5424c8346a6bff3dc512c6339687763d7478ac27a771a3ec36f249236415c017
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.15
|
Release files / medlink_pylib-0.0.19-py3-none-any.whl
| Download URL | medlink_pylib-0.0.19-py3-none-any.whl |
|---|---|
| Size | 29.8 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
92ba815b610f2518b2ab621078713ace3d521ec63829bf1d9b4851375b61bbf8
|
|
BLAKE2b-256 checksum How to use checksums |
113bc70093d7bf2466e8f0f20627fdf82f616d4dd15cf4374f7c8c91752d64a0
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.15
|
Security for medlink-pylib 0.0.19
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.