{"id":13671490,"url":"https://github.com/revalo/sharp","last_synced_at":"2025-12-25T15:56:30.599Z","repository":{"id":57430725,"uuid":"283026654","full_name":"revalo/sharp","owner":"revalo","description":"Automatic REST API code generation for Python Flask and JavaScript 🕸","archived":false,"fork":false,"pushed_at":"2021-06-13T16:31:30.000Z","size":24,"stargazers_count":104,"open_issues_count":2,"forks_count":2,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-04-10T18:46:50.565Z","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":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/revalo.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-07-27T22:00:07.000Z","updated_at":"2025-02-15T13:29:34.000Z","dependencies_parsed_at":"2022-08-27T22:30:34.265Z","dependency_job_id":null,"html_url":"https://github.com/revalo/sharp","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/revalo%2Fsharp","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/revalo%2Fsharp/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/revalo%2Fsharp/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/revalo%2Fsharp/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/revalo","download_url":"https://codeload.github.com/revalo/sharp/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":251187141,"owners_count":21549593,"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-08-02T09:01:10.942Z","updated_at":"2025-12-25T15:56:30.586Z","avatar_url":"https://github.com/revalo.png","language":"Python","funding_links":[],"categories":["Python"],"sub_categories":[],"readme":"# Sharp\n\nSharp is an automatic API generation library for Python Flask and JavaScript.\n\nYou write functions in the backend, and Sharp generates the necessary JavaScript to make\nAPI calls to those functions. Sharp also validates argument types based on Python type\nhints,\n\n```python\n@sharp.function()\ndef add(a: int, b: int):\n    return a + b\n\nsharp.generate(\"api.js\")\n```\n\nNow `api.js` can be used from a JavaScript client,\n\n```js\nconst result = await API.add(4, 3);\n```\n\n## Install\n\n```\npip install Flask-Sharp\n```\n\n## Basic Example\n\nServer-side code,\n\n```python\napp = Flask(__name__)\nsharp = Sharp(app)\n\n@sharp.function()\ndef add(a: int, b: int):\n    return a + b\n```\n\nSharp can be combined with a modern frontend framework and any web asset bundler, the code-gen is emmitted to a standalone JavaScript file,\n\n```python\nsharp.generate(\"src/js/sharp.gen.js\")\n```\n\nAnd your front-end JavaScript is automatically generated and can be used as,\n\n```js\nconst result = await API.add(4, 3);\n```\n\nOn the backend Sharp will automatically validate that both `a` and `b` parameters are valid `ints`.\n\nAll Sharp messages are in plain JSON, producing human-readable messages and API routes.\n\nFor a more fully fledged example, please see the `example/` directory.\n\n## Naming Routes\n\nBy default Sharp will try to name routes by combining the prefix with the function name.\nHowever, Sharp can also name routes based on filenames and any arbitrary custom naming\nfunction,\n\n```python\nfrom sharp import Sharp, naming\n\nsrp = Sharp(app, prefix=\"/api\", naming=naming.file_based)\n```\n\nIn this example, Sharp will name a function names `add` in a file called `math.py`\nas `/api/math/add`.\n\n## Type Checking\n\nSharp can verify basic Python type-hints and deal with default variables,\n\n```python\n@srp.function()\ndef repeat(name: str, times: int = 5):\n    return name * times\n\n\n@srp.function()\ndef reverse(names: List[str]):\n    return names[::-1]\n```\n\n## Errors\n\nIf Sharp notices a missing parameter or a wrong type, it will generate a JSON response\nbody `{\"error\": \"Message\"}` with a response code 400. To throw errors within a sharp\nfunction,\n\n```python\nfrom sharp.error import error\n\n@sharp.function()\ndef add(a: int, b: int):\n    if a \u003c 0:\n        return error(\"a cannot be negative.\")\n\n    return a + b\n```\n\nAll API calls from the client return a promise. Errors can be caught with a try-catch or\na `catch` promise callback.\n\n```js\nAPI.add(-4, 3).then((r) =\u003e {\n    // r is the result of the function.\n}).catch((e) =\u003e {\n    // e is the error message.\n});\n```\n\n## License\n\nCopyright (c) 2020 Shreyas Kapur. Released under MIT License.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frevalo%2Fsharp","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frevalo%2Fsharp","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frevalo%2Fsharp/lists"}