{"id":15752539,"url":"https://github.com/remram44/api_stats","last_synced_at":"2025-03-31T07:27:03.418Z","repository":{"id":57410941,"uuid":"43158583","full_name":"remram44/api_stats","owner":"remram44","description":"Records statistics from an API endpoint","archived":false,"fork":false,"pushed_at":"2016-08-29T16:24:44.000Z","size":20,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-28T21:11:16.485Z","etag":null,"topics":["api-client","statistics"],"latest_commit_sha":null,"homepage":null,"language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsd-3-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/remram44.png","metadata":{"files":{"readme":"README.rst","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2015-09-25T16:07:41.000Z","updated_at":"2017-09-05T15:33:49.000Z","dependencies_parsed_at":"2022-09-04T18:11:12.744Z","dependency_job_id":null,"html_url":"https://github.com/remram44/api_stats","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/remram44%2Fapi_stats","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/remram44%2Fapi_stats/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/remram44%2Fapi_stats/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/remram44%2Fapi_stats/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/remram44","download_url":"https://codeload.github.com/remram44/api_stats/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246431656,"owners_count":20776260,"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":["api-client","statistics"],"created_at":"2024-10-04T07:02:48.391Z","updated_at":"2025-03-31T07:27:03.399Z","avatar_url":"https://github.com/remram44.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"api_stats tool\n==============\n\napi_stats is a Python tool aimed at recording statistics from an API endpoint. For example, the GitHub API gives out a single number of downloads for each release; by running this tool, you can easily graph rolling averages and historical figures.\n\nQuickstart\n----------\n\napi_stats loads a \"configuration file\" that tells it what to fetch and which fields to record. This file is a Python script that will be loaded by api_stats, with a single global ``stats`` that acts as the interface with the program. This interface currently offers two functions: ``record(key, value)``, and ``get_json(url)``.\n\nHere is an example configuration file, that records the number of downloads of each file from GitHub releases:\n\n..  code-block:: python\n\n    releases = stats.get_json(\n        \"https://api.github.com/repos/remram44/api_stats/releases\")\n    for release in releases:\n        relname = release.get('tag_name') or release['name']\n        for asset in release['assets']:\n            stats.record('%s/%s' % (relname, asset['name']),\n                         asset['download_count'])\n\nThen you can plot the data, for example using matplotlib:\n\n..  code-block:: bash\n\n    python -m api_stats.plot -m '^(.+)$' 'api_stats:\\g\u003c1\u003e' data.jsonl\n\nA more complex example\n----------------------\n\nYou might want to use functions to factor the retrieval of data points from a specific source:\n\n..  code-block:: python\n\n    def github(repo):\n        releases = stats.get_json(\n            \"https://api.github.com/repos/%s/releases\" % repo)\n        for release in releases:\n            if release['draft']:\n                continue\n            relname = release.get('tag_name') or release['name']\n            for asset in release['assets']:\n                stats.record('github/%s/%s/%s' % (repo, relname, asset['name']),\n                             asset['download_count'])\n\n\n    github('VisTrails/VisTrails')\n    github('remram44/api_stats')\n\n\n    def pypi(pkg):\n        releases = stats.get_json(\n            \"https://pypi.python.org/pypi/%s/json\" % pkg)['releases']\n        for relname, release in releases.items():\n            for asset in release:\n                stats.record('pypi/%s/%s/%s' % (pkg, relname, asset['filename']),\n                             asset['downloads'])\n\n\n    pypi('VisTrails')\n    pypi('api_stats')\n\nThis will record data under ``pypi/\u003cpkg_name\u003e/\u003cversion\u003e/\u003cfilename\u003e`` and ``github/\u003cowner\u003e/\u003crepo\u003e/\u003cversion\u003e/\u003cfilename\u003e``. You can then plot the data, one figure per project, aggregated by version but adding PyPI and GitHub together, using:\n\n..  code-block:: bash\n\n    python -m api_stats.plot \\\n        -m '^pypi/([^/]+)/([^/]+)/.+$' '\\g\u003c1\u003e:\\g\u003c2\u003e' \\\n        -m '^github/[^/]+/([^/]+)/v([^/]+)/.+$' '\\g\u003c1\u003e:\\g\u003c2\u003e' \\\n        releases.jsonl\n\n..  image:: https://cloud.githubusercontent.com/assets/426784/10232482/0550d7e0-6857-11e5-835f-86631dd89b4d.png\n    :alt: Example Plot with matplotlib\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fremram44%2Fapi_stats","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fremram44%2Fapi_stats","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fremram44%2Fapi_stats/lists"}