{"id":17823278,"url":"https://github.com/purarue/hpi_api","last_synced_at":"2025-10-11T10:33:45.109Z","repository":{"id":94610249,"uuid":"322933298","full_name":"purarue/HPI_API","owner":"purarue","description":"An automatic JSON API for HPI","archived":false,"fork":false,"pushed_at":"2024-10-25T17:09:08.000Z","size":56,"stargazers_count":15,"open_issues_count":2,"forks_count":1,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-15T00:32:58.319Z","etag":null,"topics":["data","json-api","personal-api","quantified-self"],"latest_commit_sha":null,"homepage":"https://github.com/karlicoss/HPI","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/purarue.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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2020-12-19T20:34:17.000Z","updated_at":"2024-12-31T08:03:36.000Z","dependencies_parsed_at":"2024-10-27T19:39:38.507Z","dependency_job_id":"f6f7c800-1326-48ec-a44b-8b13c38b4a6a","html_url":"https://github.com/purarue/HPI_API","commit_stats":null,"previous_names":["purarue/hpi_api","seanbreckenridge/hpi_api"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/purarue%2FHPI_API","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/purarue%2FHPI_API/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/purarue%2FHPI_API/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/purarue%2FHPI_API/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/purarue","download_url":"https://codeload.github.com/purarue/HPI_API/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244259778,"owners_count":20424615,"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":["data","json-api","personal-api","quantified-self"],"created_at":"2024-10-27T17:57:18.819Z","updated_at":"2025-10-11T10:33:40.089Z","avatar_url":"https://github.com/purarue.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"An automatic JSON API for [HPI](https://github.com/karlicoss/HPI)\n\nThis inspects functions in each `HPI` module file, generating routes for each of them.\n\nThis provides access to the data fine, but I wouldn't recommend putting this up on the public internet as this allows anything that can make a GET request to call arbitrary functions in HPI; At least put it behind some authenticated proxy or host it on a private port\n\nThis uses [`my.core.serialize`](https://github.com/karlicoss/HPI/blob/master/my/core/serialize.py) to convert the responses to JSON, which uses [`orjson`](https://github.com/ijl/orjson) under the hood, to serialize datetimes, namedtuples and dataclasses much faster than the stdlib.\n\nIf you have any suggestions/trouble with getting this to work, feel free to open an Issue/PR!\n\n---\n\n### Installation\n\nRequires `python3.7+`\n\nTo install with pip, run:\n\n    pip install git+https://github.com/purarue/HPI_API\n\n---\n\n### Usage\n\nFor each function in an HPI module, this generates a HTTP route. For example, if you had the module `my.reddit`, which had a function `comments`, which returned an iterator/list of your `reddit` comments, requesting `/my/reddit/comments` would call that function.\n\n- If the function fails to be called, it returns an HTTP code \u003e 400.\n- If the function succeeds\n  - and this returns a primitive, a `dict` or this is the stats function, it returns the value directly\n  - otherwise, this assumes its returning some iterable event-like response, supporting the following GET params:\n    - limit: int (defaults to 50) - how many items to return per page\n    - page: int (defaults to 1) - which page to return\n    - sort: str \"attribute_name\" - some getattr/dictionary key on the object returned from the HPI function), e.g. \"dt\", or \"date\", to sort by date. If not provided, returns the same order as the underlying HPI function\n    - order_by: one of [asc, desc] (default: asc) - to sort by ascending or descending order\n\nTheres no limit to the `limit` param, if you wanted to grab all the data, you can always do something like `?limit=99999999999999999\u0026page=1`\n\nThough I'm not a huge fan of pagination, the `limit` included anyways. Otherwise, if not behind `cachew`, some responses may take a _long_ time to compute\n\nAfter installing, you can run this server with:\n\n```bash\n$ python3 -m my_api server  # or `hpi_api server`\n```\n\nTo list the routes, you can run one of the following:\n\n```bash\n$ curl 'localhost:5050/routes'\n$ hpi_api list-modules --functions\n$ hpi_api server --print-routes\n```\n\nHere are some examples:\n\n```bash\n$ curl 'localhost:5050/my/zsh/history?limit=3'\n{\"items\":[{\"command\":\"z\",\"dt\":\"Mon, 18 May 2020 08:23:22 GMT\",\"duration\":0},{\"command\":\"en env_config.zsh\",\"dt\":\"Mon, 18 May 2020 08:23:22 GMT\",\"duration\":0},{\"command\":\"ls\",\"dt\":\"Mon, 18 May 2020 08:23:22 GMT\",\"duration\":0}],\"limit\":3,\"page\":1}\n$ curl 'localhost:5050/my/github/all/events?limit=1' | jq -r '.items | .[0]'\n{\n  \"body\": \"Note: This is used for [gitopen](https://github.com/purarue/dotfiles/commit/4c57fd97cbb2605e63d0cf5d2af37039fe6e6d35)\",\n  \"dt\": \"Thu, 14 Feb 2019 21:05:40 GMT\",\n  \"eid\": \"commoit_comment_https://github.com/purarue/mac-dotfiles/commit/d4ac3c30dd3df1b626f92eb61f651a27852ff86f#commitcomment-32324943\",\n  \"is_bot\": false,\n  \"link\": \"https://github.com/purarue/mac-dotfiles/commit/d4ac3c30dd3df1b626f92eb61f651a27852ff86f#commitcomment-32324943\",\n  \"summary\": \"commented on https://github.com/purarue/mac-dotfiles/commit/d4ac3c30dd3df1b626f92eb61f651a27852ff86f#commitcomment-32324943\"\n}\n$ curl localhost:5050/my/zsh/stats\n{\"value\":{\"history\":{\"count\":266722}}}\n$ curl 'localhost:5050/my/zsh/history?sort=command\u0026order_by=desc\u0026limit=2'\n{\"items\":[{\"command\":\"~/code/plaintext-playlist/plainplay | basename\",\"dt\":\"Thu, 28 May 2020 06:52:58 GMT\",\"duration\":3},{\"command\":\"~/code/plaintext-playlist/plainplay | basename\",\"dt\":\"Thu, 28 May 2020 06:52:39 GMT\",\"duration\":2}],\"limit\":2,\"page\":1}\n```\n\n---\n\n### Configuration\n\nTo change the port this runs on, you can use the `--port` flag to change the port this runs on (default is `5050`) when running with `hpi_api server`.\n\nBy default, this allows CORS requests, you can pass the `--no-cors` flag to disable that.\n\nIf you want to customize the application further, you can import the generated Flask application to add routes, or run it with another WSGI compatible server, like [`waitress`](https://pypi.org/project/waitress/):\n\n```python\nfrom my_api.server import generate_server\n\napp = generate_server()\n\n## ... configure whatever you want, add routes to Flask app\n\nif __name__ == \"__main__\":\n    from waitress import serve\n    serve(app, port=8123, host=\"0.0.0.0\")\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpurarue%2Fhpi_api","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpurarue%2Fhpi_api","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpurarue%2Fhpi_api/lists"}