{"id":24738640,"url":"https://github.com/zweifisch/klar","last_synced_at":"2025-10-10T07:32:57.709Z","repository":{"id":14206992,"uuid":"16913686","full_name":"zweifisch/klar","owner":"zweifisch","description":"a micro web framework built for fun","archived":false,"fork":false,"pushed_at":"2024-04-11T09:02:42.000Z","size":284,"stargazers_count":2,"open_issues_count":2,"forks_count":1,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-09-28T09:03:33.687Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"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/zweifisch.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,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2014-02-17T13:28:58.000Z","updated_at":"2015-04-12T08:41:17.000Z","dependencies_parsed_at":"2025-09-08T13:22:03.564Z","dependency_job_id":"ff6cc9ce-234d-482f-8f10-382aee72ff3b","html_url":"https://github.com/zweifisch/klar","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/zweifisch/klar","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zweifisch%2Fklar","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zweifisch%2Fklar/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zweifisch%2Fklar/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zweifisch%2Fklar/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/zweifisch","download_url":"https://codeload.github.com/zweifisch/klar/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zweifisch%2Fklar/sbom","scorecard":{"id":1237253,"data":{"date":"2025-08-04","repo":{"name":"github.com/zweifisch/klar","commit":"b04f635e39fc89625cf810286e5a89f8f7ddf434"},"scorecard":{"version":"v5.2.1-28-gc1d103a9","commit":"c1d103a9bb9f635ec7260bf9aa0699466fa4be0e"},"score":3,"checks":[{"name":"Maintained","score":0,"reason":"0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0","details":null,"documentation":{"short":"Determines if the project is \"actively maintained\".","url":"https://github.com/ossf/scorecard/blob/c1d103a9bb9f635ec7260bf9aa0699466fa4be0e/docs/checks.md#maintained"}},{"name":"Packaging","score":-1,"reason":"packaging workflow not detected","details":["Warn: no GitHub/GitLab publishing workflow detected."],"documentation":{"short":"Determines if the project is published as a package that others can easily download, install, easily update, and uninstall.","url":"https://github.com/ossf/scorecard/blob/c1d103a9bb9f635ec7260bf9aa0699466fa4be0e/docs/checks.md#packaging"}},{"name":"Binary-Artifacts","score":10,"reason":"no binaries found in the repo","details":null,"documentation":{"short":"Determines if the project has generated executable (binary) artifacts in the source repository.","url":"https://github.com/ossf/scorecard/blob/c1d103a9bb9f635ec7260bf9aa0699466fa4be0e/docs/checks.md#binary-artifacts"}},{"name":"Code-Review","score":0,"reason":"Found 0/30 approved changesets -- score normalized to 0","details":null,"documentation":{"short":"Determines if the project requires human code review before pull requests (aka merge requests) are merged.","url":"https://github.com/ossf/scorecard/blob/c1d103a9bb9f635ec7260bf9aa0699466fa4be0e/docs/checks.md#code-review"}},{"name":"Dangerous-Workflow","score":-1,"reason":"no workflows found","details":null,"documentation":{"short":"Determines if the project's GitHub Action workflows avoid dangerous patterns.","url":"https://github.com/ossf/scorecard/blob/c1d103a9bb9f635ec7260bf9aa0699466fa4be0e/docs/checks.md#dangerous-workflow"}},{"name":"Token-Permissions","score":-1,"reason":"No tokens found","details":null,"documentation":{"short":"Determines if the project's workflows follow the principle of least privilege.","url":"https://github.com/ossf/scorecard/blob/c1d103a9bb9f635ec7260bf9aa0699466fa4be0e/docs/checks.md#token-permissions"}},{"name":"SAST","score":0,"reason":"no SAST tool detected","details":["Warn: no pull requests merged into dev branch"],"documentation":{"short":"Determines if the project uses static code analysis.","url":"https://github.com/ossf/scorecard/blob/c1d103a9bb9f635ec7260bf9aa0699466fa4be0e/docs/checks.md#sast"}},{"name":"Pinned-Dependencies","score":-1,"reason":"no dependencies found","details":null,"documentation":{"short":"Determines if the project has declared and pinned the dependencies of its build process.","url":"https://github.com/ossf/scorecard/blob/c1d103a9bb9f635ec7260bf9aa0699466fa4be0e/docs/checks.md#pinned-dependencies"}},{"name":"CII-Best-Practices","score":0,"reason":"no effort to earn an OpenSSF best practices badge detected","details":null,"documentation":{"short":"Determines if the project has an OpenSSF (formerly CII) Best Practices Badge.","url":"https://github.com/ossf/scorecard/blob/c1d103a9bb9f635ec7260bf9aa0699466fa4be0e/docs/checks.md#cii-best-practices"}},{"name":"Security-Policy","score":0,"reason":"security policy file not detected","details":["Warn: no security policy file detected","Warn: no security file to analyze","Warn: no security file to analyze","Warn: no security file to analyze"],"documentation":{"short":"Determines if the project has published a security policy.","url":"https://github.com/ossf/scorecard/blob/c1d103a9bb9f635ec7260bf9aa0699466fa4be0e/docs/checks.md#security-policy"}},{"name":"Fuzzing","score":0,"reason":"project is not fuzzed","details":["Warn: no fuzzer integrations found"],"documentation":{"short":"Determines if the project uses fuzzing.","url":"https://github.com/ossf/scorecard/blob/c1d103a9bb9f635ec7260bf9aa0699466fa4be0e/docs/checks.md#fuzzing"}},{"name":"Vulnerabilities","score":10,"reason":"0 existing vulnerabilities detected","details":null,"documentation":{"short":"Determines if the project has open, known unfixed vulnerabilities.","url":"https://github.com/ossf/scorecard/blob/c1d103a9bb9f635ec7260bf9aa0699466fa4be0e/docs/checks.md#vulnerabilities"}},{"name":"License","score":10,"reason":"license file detected","details":["Info: project has a license file: LICENSE:0","Info: FSF or OSI recognized license: MIT License: LICENSE:0"],"documentation":{"short":"Determines if the project has defined a license.","url":"https://github.com/ossf/scorecard/blob/c1d103a9bb9f635ec7260bf9aa0699466fa4be0e/docs/checks.md#license"}},{"name":"Signed-Releases","score":-1,"reason":"no releases found","details":null,"documentation":{"short":"Determines if the project cryptographically signs release artifacts.","url":"https://github.com/ossf/scorecard/blob/c1d103a9bb9f635ec7260bf9aa0699466fa4be0e/docs/checks.md#signed-releases"}},{"name":"Branch-Protection","score":0,"reason":"branch protection not enabled on development/release branches","details":["Warn: branch protection not enabled for branch 'master'"],"documentation":{"short":"Determines if the default and release branches are protected with GitHub's branch protection settings.","url":"https://github.com/ossf/scorecard/blob/c1d103a9bb9f635ec7260bf9aa0699466fa4be0e/docs/checks.md#branch-protection"}}]},"last_synced_at":"2025-09-08T13:38:09.002Z","repository_id":14206992,"created_at":"2025-09-08T13:38:09.002Z","updated_at":"2025-09-08T13:38:09.002Z"},"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":279003189,"owners_count":26083533,"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","status":"online","status_checked_at":"2025-10-10T02:00:06.843Z","response_time":62,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":"2025-01-27T22:55:10.757Z","updated_at":"2025-10-10T07:32:57.402Z","avatar_url":"https://github.com/zweifisch.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# klar\n\na micro web framework built for fun\n\n* argument annotation\n* jsonschema intergration\n\n```py\nfrom klar import App\n\napp = App()\n\n@app.get('/hello/\u003cname\u003e')\ndef hello(name: str, times: int = 1):\n\treturn \"hello \" * times + name\n```\n\nrun it using [wsgi-supervisor](https://github.com/zweifisch/wsgi-supervisor)\n\n```sh\nwsgi-supervisor app:app\n```\n\n```sh\n$ curl 'localhost:3000/hello/klar?times=2'\nhello hello klar\n```\n\n## custom types using jsonschema\n\n```python\nproduct = {\n\t\"type\": \"object\"\n\t\"properties\": {\n\t\t\"name\": {\n\t\t\t\"type\": \"string\"\n\t\t},\n\t\t\"price\": {\n\t\t\t\"type\": \"number\"\n\t\t},\n\t},\n\t\"additionalProperties\": False,\n}\n\n@app.post('/product')\ndef create(body: product, db):\n\tdb.products.insert(body)\n\treturn {\"ok\": True}\n```\n\nschemas can and should be imported from json or yaml files\n\n```\n|--app.py\n|--schemas.json\n```\n\nproduct in schema.json\n\n```\n{\n\tproduct: {...}\n}\n```\n\n```python\nfrom schemas import product\n\n@app.post('/product')\ndef create(body: product):\n\tpass\n```\n\n## dependency injection\n\nprovide a custom dependency using decorator\n\n```python\n@app.provide('db')\ndef get_db_connection():\n\tconn = SomeDB(url=\"localhost:3349\")\n\treturn conn\n\nimport redis\napp.provide('cache', (redis.Redis, {'host': 'localhost'}))\n```\n\nusing `db` and `cache` in request handler\n\n```python\n@get('/article/\u003carticle_id\u003e')\ndef get_article(article_id:int, db, cache):\n    pass\n```\n\npredefined components:\n\n* req\n* session\n* cookie\n* router\n\n## rest\n\n```python\nfrom resource import product, catalog\n\napp = App()\n\napp.resources(product, catalog, prefix=\"/v1\")\n\nif __name__ == '__main__':\n\tapp.run()\n```\n\nin product\n\n```python\nfrom schema import product\n\n# curl -X POST $host/v1/product -d @body\ndef create(body: product, db):\n\treturn db.products.insert(body)\n\n# curl $host/v1/product/$id\ndef show(product_id: str):\n\titem = db.products.find_one({_id: product_id})\n\treturn item if item else 404\n\n# curl $host/v1/product?shift=10\u0026limit=10\ndef query(shift: int, limit: int, db):\n\treturn db.products.find().skip(shift).limit(shift)\n\n# curl -X PATCH $host/v1/product/$id -d @body\ndef modify(body: product, product_id: str):\n\treturn db.products.update({_id: product_id}, {'$set': body})\n\n# curl -X PUT $host/v1/product/$id -d @body\ndef replace(body: product, product_id: str):\n\treturn db.products.update({_id: product_id}, body)\n\n# curl -X DELETE $host/v1/product/$id\ndef destroy(product_id: str):\n\treturn db.products.delete({_id: product_id})\n```\n\n### custom method\n\n```python\nfrom klar import method\n\n@method('patch')\ndef like(product_id):\n\treturn db.products.update({_id: product_id}, {'$inc': {'likes': 1}})\n\n# curl -X PATCH $host/v1/product/$id/like\n```\n\n## events\n\nlistening for an event\n\n```python\n@on(404)\ndef not_found(req, res):\n\tprint('%s not found' % req.path)\n    res.body = \"%s not found on this server\" % req.path\n```\n\n### custom events\n\n```python\n@on('user-login')\ndef onlogin(userid, db):\n\tprint('user: %s logged in' % userid)\n\tdb.users.update({_id:userid}, {'$inc': {'logincount': 1}})\n```\n\nemit an event\n\n```python\ndef login(emitter):\n\temitter.emit('user-login', userid=id)\n```\n\n## post processing\n\n```python\ndef jsonp(req, res):\n    callback = req.query.get('callback')\n    if callback:\n        res.body = \"%s(%s)\" % (callback, json.dumps(body))\n        res.headers[\"Content-Type\"] = \"application/javascript\"\n\n@app.get('/resource') -\u003e jsonp:\n\treturn {\"key\": \"value\"}\n```\n\nmore than one processors:\n\n```python\n@app.get('/resource') -\u003e (jsonp, etag):\n\treturn {\"key\": \"value\"}\n```\n\n## template rendering\n\n```\n|--app.py\n|--templates\n   |--home.html\n```\n\n```python\nimport templates.home\n\n@app.get('/') -\u003e templates.home:\n\treturn {\"key\": \"value\"}\n```\n\n`templates.home` accecpts an optional dict as argument\nit's basically equivalent to this:\n\n```python\n@app.get('/'):\n\treturn templates.home({\"key\": \"value\"})\n```\n\n### mustache\n\ndepends on pystache, `pip install pystache`\n\nuse `.mustache` as extension\n\n```\n|--templates\n   |--home.mustache\n```\n\n```python\nimport templates.home\n```\n\n## session\n\nsession depends on `cache`, but klar does't has it builtin\n\nto use redis as session backend:\n\n```python\nimport redis\n\n@app.provide('cache')\ndef cache():\n\treturn redis.Redis(host='localhost', port=6379, db=0)\n```\n\nor\n\n```python\napp.privide('cache', (redis.Redis, {'host': 'localhost'}))\n```\n\n### use session\n\n```python\n@app.post('/login')\ndef login(body, session):\n\t# check body.username and body.password\n\tif founduser:\n\t\tsession.set('userid', userid)\n\n@app.post('/login')\ndef logout(session):\n\tsession.destroy()\n\n@app.get('/admin')\ndef admin(session):\n\tif session.get('userid'):\n\t\tpass\n```\n\n## cookies\n\n```python\ncookies.get(key, default)\ncookies.set(key, value)\ncookies.delete(key)\n\ncookies.set(key, value, httponly=True)\ncookies.set_for_30_days(key, value)\n```\n\n## serving static files\n\nshould only be used in development enviroment\n\n```\napp.static('/public/')\n```\n\n```\napp.static('/public/', 'path/to/public/dir')\n```\n\n## config\n\nconfig file path will be read from enviroment variable `$CONFIG`\n\nif it's empty config.py will be loaded\n\nconfig.py\n\n```python\nmongo = {\n    \"host\": \"127.0.0.1\"\n    \"port\": 27017\n}\n```\n\n```python\nfrom pymongo import MongoClient\n\n@app.provide('db')\ndef db(config):\n    return MongoClient(**config.mongo)\n```\n\n## reversed routing\n\n```python\n@app.get('user/\u003cid\u003e')\ndef user(id:str):\n    pass\n```\n\nget a link to previous handler\n\n```\ndef another_handler(router):\n    href = router.path_for('user', id=3221)\n```\n\n## custom json encoder\n\n```python\nfrom bson.objectid import ObjectId\n\n@app.json_encode(ObjectId)\ndef encode_objectid(obj):\n    return str(obj)\n```\n\nby default `Iterable` is converted to `list`\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzweifisch%2Fklar","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fzweifisch%2Fklar","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzweifisch%2Fklar/lists"}