Metadata-Version: 2.1
Name: esmerald_timing
Version: 0.1.0
Summary: The scheduler that nobody wants but every application needs.
Project-URL: Homepage, https://github.com/dymmond/esmerald-timing
Project-URL: Documentation, https://github.com/dymmond/esmerald-timing
Project-URL: Changelog, https://dymmond.com/esmerald-timing/changelog/
Project-URL: Funding, https://github.com/sponsors/tarsil
Project-URL: Source, https://github.com/dymmond/esmerald-timing
Author-email: Tiago Silva <tiago.arasilva@gmail.com>
License-Expression: MIT
License-File: LICENSE
Keywords: api,apscheduler,asgi,cron,esmerald,fastapi,framework,http,machine learning,ml,openapi,pydantic,rest,scheduler,starlette,websocket
Classifier: Development Status :: 4 - Beta
Classifier: Environment :: Web Environment
Classifier: Framework :: AnyIO
Classifier: Framework :: AsyncIO
Classifier: Intended Audience :: Developers
Classifier: Intended Audience :: Information Technology
Classifier: Intended Audience :: System Administrators
Classifier: License :: OSI Approved :: MIT License
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3 :: Only
Classifier: Programming Language :: Python :: 3.7
Classifier: Programming Language :: Python :: 3.8
Classifier: Programming Language :: Python :: 3.9
Classifier: Programming Language :: Python :: 3.10
Classifier: Topic :: Internet
Classifier: Topic :: Internet :: WWW/HTTP
Classifier: Topic :: Internet :: WWW/HTTP :: HTTP Servers
Classifier: Topic :: Software Development
Classifier: Topic :: Software Development :: Libraries
Classifier: Topic :: Software Development :: Libraries :: Application Frameworks
Classifier: Topic :: Software Development :: Libraries :: Python Modules
Classifier: Typing :: Typed
Requires-Python: >=3.7
Requires-Dist: asyncio<4.0.0,>=3.4.3
Provides-Extra: all
Requires-Dist: timing-asgi<4.0.0,>=0.3.0; extra == 'all'
Provides-Extra: dev
Requires-Dist: autoflake<3.0.0,>=1.4.0; extra == 'dev'
Requires-Dist: black<23.0.0,>=22.10.0; extra == 'dev'
Requires-Dist: flake8<7.0.0,>=3.8.3; extra == 'dev'
Requires-Dist: isort<6.0.0,>=5.0.6; extra == 'dev'
Requires-Dist: mypy<2.0.0,>=0.982; extra == 'dev'
Requires-Dist: pre-commit<3.0.0,>=2.17.0; extra == 'dev'
Requires-Dist: watchfiles<0.20.0,>=0.16.1; extra == 'dev'
Provides-Extra: test
Requires-Dist: asynctest<1.0.0,>=0.13.0; extra == 'test'
Requires-Dist: esmerald>=0.5.4; extra == 'test'
Requires-Dist: pytest-cov<5.0.0,>=2.12.0; extra == 'test'
Requires-Dist: pytest<8.0.0,>=7.1.3; extra == 'test'
Description-Content-Type: text/markdown

# Esmerald Datadog

<p align="center">
  <a href="https://esmerald.dymmond.com"><img src="https://res.cloudinary.com/dymmond/image/upload/v1671718628/esmerald/img/logo-gr_oyr4my.png" alt='Esmerald'></a>
</p>

<p align="center">
    <em>🚀 ASGI integration with TimingASGIMiddleware for Esmerald . 🚀</em>
</p>

<p align="center">
<a href="https://github.com/dymmond/esmerald-timing/workflows/Test%20Suite/badge.svg?event=push&branch=main" target="_blank">
    <img src="https://github.com/dymmond/esmerald-timing/workflows/Test%20Suite/badge.svg?event=push&branch=main" alt="Test Suite">
</a>

<a href="https://pypi.org/project/esmerald-timing" target="_blank">
    <img src="https://img.shields.io/pypi/v/esmerald?color=%2334D058&label=pypi%20package" alt="Package version">
</a>

<a href="https://pypi.org/project/esmerald-timing" target="_blank">
    <img src="https://img.shields.io/pypi/pyversions/esmerald-timing.svg?color=%2334D058" alt="Supported Python versions">
</a>
</p>

---

**Esmerald Documentation**: [https://esmerald.dymmond.com](https://esmerald.dymmond.com) 📚

**Esmerald Source Code**: [https://github.com/dymmond/esmerald](https://github.com/dymmond/esmerald)

---

## Motivation

This is an Esmerald integration to use the [TimingMiddleware](https://github.com/steinnes/timing-asgi).

[TimingMiddleware](https://github.com/steinnes/timing-asgi) for ASGI is useful for automatic
instrumentation of ASGI endpoints.

This package is an extension allowing the integration with Esmerald.

## Requirements

* Python 3.7 +
* [Esmerald](https://esmerald.dymmond.com)

## Usage

```python
import uvicorn
from esmerald_timing.integrations import EsmeraldScopeToName
from timing_asgi import TimingClient, TimingMiddleware

from esmerald import Gateway, Request, get
from esmerald.applications import Esmerald
from esmerald.responses import PlainTextResponse


class PrintTimings(TimingClient):
    def timing(self, metric_name, timing, tags):
        print(metric_name, timing, tags)


@get("/")
def homepage(request: Request) -> PlainTextResponse:
    return PlainTextResponse("Welcome to Esmerald!")


app = Esmerald(routes=[Gateway(handler=homepage)])

app.add_middleware(
    TimingMiddleware,
    client=PrintTimings(),
    metric_namer=EsmeraldScopeToName(prefix="myapp", esmerald_app=app),
)

if __name__ == "__main__":
    uvicorn.run(app)
```

Running this example and sending some requests:

```shell
$ python app.py
INFO:     Started server process [18769]
INFO:     Waiting for application startup.
INFO:     Application startup complete.
INFO:     Uvicorn running on http://127.0.0.1:8000 (Press CTRL+C to quit)
INFO:     127.0.0.1:58132 - "GET / HTTP/1.1" 200 OK
myapp.__main__.homepage 0.0009038448333740234 ['http_status:200', 'http_method:GET', 'time:wall']
myapp.__main__.homepage 0.0008970000000000367 ['http_status:200', 'http_method:GET', 'time:cpu']
myapp.favicon.ico 0.0006134510040283203 ['http_status:404', 'http_method:GET', 'time:wall']
myapp.favicon.ico 0.0006120000000000569 ['http_status:404', 'http_method:GET', 'time:cpu']
INFO:     127.0.0.1:58132 - "GET / HTTP/1.1" 200 OK
myapp.__main__.homepage 0.000881195068359375 ['http_status:200', 'http_method:GET', 'time:wall']
myapp.__main__.homepage 0.0008829999999999671 ['http_status:200', 'http_method:GET', 'time:cpu']
INFO:     127.0.0.1:58132 - "GET / HTTP/1.1" 200 OK
myapp.__main__.homepage 0.0014600753784179688 ['http_status:200', 'http_method:GET', 'time:wall']
myapp.__main__.homepage 0.0014729999999998356 ['http_status:200', 'http_method:GET', 'time:cpu']
```