{"id":22998254,"url":"https://github.com/uswitch/service-standard-python","last_synced_at":"2025-04-02T13:24:12.121Z","repository":{"id":50092008,"uuid":"305976064","full_name":"uswitch/service-standard-python","owner":"uswitch","description":"The RVU Service Standard Library for Python services.","archived":false,"fork":false,"pushed_at":"2021-06-04T14:36:39.000Z","size":25,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":11,"default_branch":"main","last_synced_at":"2025-02-08T04:29:13.206Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/uswitch.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2020-10-21T09:38:15.000Z","updated_at":"2020-11-25T15:12:48.000Z","dependencies_parsed_at":"2022-08-03T18:45:22.383Z","dependency_job_id":null,"html_url":"https://github.com/uswitch/service-standard-python","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/uswitch%2Fservice-standard-python","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/uswitch%2Fservice-standard-python/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/uswitch%2Fservice-standard-python/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/uswitch%2Fservice-standard-python/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/uswitch","download_url":"https://codeload.github.com/uswitch/service-standard-python/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246820814,"owners_count":20839304,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-12-15T06:12:25.344Z","updated_at":"2025-04-02T13:24:12.098Z","avatar_url":"https://github.com/uswitch.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# service-standard-python\nThe Service Standard Library for Python services.\n\nThis library covers implementations for various areas documented in the [Service Standard](https://github.com/uswitch/service-standard-docs)\n\n## Setup\n\nAny build environment will need access to this repo.\n\n### Via pipenv\n```\npipenv install -e \"git+https://github.com/uswitch/service-standard-python.git@v0.3#egg=service-standard-python\"\n```\nYour Pipfile should have a line like:\n```\nservice-standard-python = {editable = true, git = \"https://github.com/uswitch/service-standard-python.git\", ref = \"v0.3\"}\n```\n### Via pip\n```\npip install -e \"git+https://github.com/uswitch/service-standard-python@v0.3#egg=service-standard-python\"\n```\n\nYour requirements.txt should have a line specifying a link to the git repo.\n\n## Usage\n\n### HTTP requests \u0026 duration\nTo track Flask HTTP requests, use the flask wrapper for automatic timing and labelling:\n```python\nfrom service_standard_python.flask import service_standard_flask_wrapper\n\n...\n\n@app.route('/', methods=['GET'])\n@service_standard_flask_wrapper\ndef myHandlerFunc():\n```\n\n### Errors\nTo count errors, use the exposed `ERRORS_TOTAL` counter:\n```python\nfrom service_standard_python.metrics import ERRORS_TOTAL\n\n...\n\ndef myErrorHandler(e):\n    ERRORS_TOTAL.labels(type=type(e).__name__).inc()\n    handleError(e)\n```\n\n### Exposing the endpoint\nFor simple apps, `add_prometheus()` easily adds a `/metrics` endpoint:\n```\nfrom service_standard_python.flask import add_prometheus\n\napp = Flask(__name__)\n\n# Add prometheus wsgi middleware to route /metrics requests\nadd_prometheus(app)\n```\n\nAlternatively, if your application already has middlewares, you can instead use the [prometheus_client](https://pypi.org/project/prometheus-client/) package directly to create an endpoint with `make_wsgi_app()` like so:\n```\napp.wsgi_app = DispatcherMiddleware(app.wsgi_app, {\n        '/other-endpoints': other_wsgi_app()\n        '/metrics': make_wsgi_app()\n    })\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fuswitch%2Fservice-standard-python","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fuswitch%2Fservice-standard-python","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fuswitch%2Fservice-standard-python/lists"}