{"id":37075202,"url":"https://github.com/francescozoccheddu/swjas","last_synced_at":"2026-01-14T08:50:55.646Z","repository":{"id":57472759,"uuid":"195909613","full_name":"francescozoccheddu/swjas","owner":"francescozoccheddu","description":"Simple WSGI JSON API Server","archived":true,"fork":false,"pushed_at":"2024-02-10T20:02:53.000Z","size":38,"stargazers_count":0,"open_issues_count":4,"forks_count":0,"subscribers_count":0,"default_branch":"master","last_synced_at":"2025-09-11T07:31:31.791Z","etag":null,"topics":["json","python","server","wsgi","wsgi-application"],"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/francescozoccheddu.png","metadata":{"files":{"readme":"README.md","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":"2019-07-09T01:27:17.000Z","updated_at":"2024-02-10T21:10:10.000Z","dependencies_parsed_at":"2022-09-19T10:20:23.034Z","dependency_job_id":null,"html_url":"https://github.com/francescozoccheddu/swjas","commit_stats":null,"previous_names":[],"tags_count":5,"template":false,"template_full_name":null,"purl":"pkg:github/francescozoccheddu/swjas","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/francescozoccheddu%2Fswjas","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/francescozoccheddu%2Fswjas/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/francescozoccheddu%2Fswjas/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/francescozoccheddu%2Fswjas/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/francescozoccheddu","download_url":"https://codeload.github.com/francescozoccheddu/swjas/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/francescozoccheddu%2Fswjas/sbom","scorecard":{"id":409031,"data":{"date":"2025-08-11","repo":{"name":"github.com/francescozoccheddu/swjas","commit":"8722ffaba28c2400b9c7b486f866d429100c204d"},"scorecard":{"version":"v5.2.1-40-gf6ed084d","commit":"f6ed084d17c9236477efd66e5b258b9d4cc7b389"},"score":2.3,"checks":[{"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/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#code-review"}},{"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/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#packaging"}},{"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/f6ed084d17c9236477efd66e5b258b9d4cc7b389/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/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#token-permissions"}},{"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/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#binary-artifacts"}},{"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/f6ed084d17c9236477efd66e5b258b9d4cc7b389/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/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#pinned-dependencies"}},{"name":"Maintained","score":0,"reason":"project is archived","details":["Warn: Repository is archived."],"documentation":{"short":"Determines if the project is \"actively maintained\".","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#maintained"}},{"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/f6ed084d17c9236477efd66e5b258b9d4cc7b389/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/f6ed084d17c9236477efd66e5b258b9d4cc7b389/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/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#fuzzing"}},{"name":"License","score":10,"reason":"license file detected","details":["Info: project has a license file: LICENSE.txt:0","Info: FSF or OSI recognized license: MIT License: LICENSE.txt:0"],"documentation":{"short":"Determines if the project has defined a license.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/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/f6ed084d17c9236477efd66e5b258b9d4cc7b389/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/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#branch-protection"}},{"name":"Vulnerabilities","score":4,"reason":"6 existing vulnerabilities detected","details":["Warn: Project is vulnerable to: PYSEC-2020-29 / GHSA-5v8v-66v8-mwm7","Warn: Project is vulnerable to: PYSEC-2014-14 / GHSA-652x-xj99-gmcc","Warn: Project is vulnerable to: GHSA-9hjg-9r4m-mvj7","Warn: Project is vulnerable to: GHSA-9wx4-h78v-vm56","Warn: Project is vulnerable to: PYSEC-2014-13 / GHSA-cfj3-7x9c-4p3h","Warn: Project is vulnerable to: PYSEC-2018-28 / GHSA-x84v-xcm2-53pg"],"documentation":{"short":"Determines if the project has open, known unfixed vulnerabilities.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#vulnerabilities"}}]},"last_synced_at":"2025-08-18T22:09:08.550Z","repository_id":57472759,"created_at":"2025-08-18T22:09:08.550Z","updated_at":"2025-08-18T22:09:08.550Z"},"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28414698,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-14T08:38:59.149Z","status":"ssl_error","status_checked_at":"2026-01-14T08:38:43.588Z","response_time":107,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.6:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"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":["json","python","server","wsgi","wsgi-application"],"created_at":"2026-01-14T08:50:54.884Z","updated_at":"2026-01-14T08:50:55.626Z","avatar_url":"https://github.com/francescozoccheddu.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# swjas\n\n\n**Simple WSGI JSON API Server**\n\n### Installation\n`pip install swjas`\n\n\n## Core\n\n### Usage\nCall `core.makeApplication` to create your WSGI application.\n- **`makeApplication`**\n    - **Parameters**\n        - `route` : *Iterable*  \n        Iterable of `(path, handler)` tuples or lists\n            - `path` : `str`  \n            Mapped URL path.  \n            Do not include scheme, authority, query or fragment.\n            - `handler` : *Callable*  \n            Object (or function) to call to handle incoming POST requests to `path`.\n                - **Parameters**\n                    - `data` : `dict`, `list`, `int`, `float`, `string`, `bool` or `None`  \n                    Deserialied JSON request body if any, otherwhise `None`\n                - **Returns**  \n                JSON serializable object or `None`.  \n                (Note: `datetime.datetime` objects have built-in serialization support)  \n                (Note: Custom objects can be serialized if they provide a `_json` property that returns a JSON serializable object)\n        - `allowEmptyRequestBody` : `bool` (`True` by default)  \n        In the case of empty or space request body, if `True` handler argument will be `None`, otherwise a `BadRequestException` will be raised.  \n        (Note: if `True` empty or space request body will not be distinguishable from `null` body)\n    - **Returns**  \n    WSGI application.\n\n### Examples\nServe using `wsgi_ref`\n```python\nfrom wsgiref.simple_server import make_server\nfrom swjas.core import makeApplication\n\n# Services\n\ndef authentication(data):\n    authenticated = data[\"username\"] == \"Francesco\" and data[\"password\"] == \"12345\"\n    return {\n        \"authenticated\": authenticated\n    }\n\ndef intDivision(data):\n    if data[\"b\"] == 0:\n        return {\n            \"error\": \"Division by zero\"\n        }\n    return {\n        \"quotient\": data[\"a\"] // data[\"b\"],\n        \"remainder\": data[\"a\"] % data[\"b\"]\n    }\n\n# Server\n\nif __name__ == \"__main__\":\n    routes = [\n        ('auth', authentication),\n        ('idiv', intDivision)\n    ]\n    server = make_server(\"localhost\", 8000, makeApplication(routes))\n    server.serve_forever()\n```\nServe using `waitress`\n```python\nimport waitress\nfrom swjas.core import makeApplication\nimport random, string\n\n# Services\n\ndef generateRandomID(data):\n    id = \"\"\n    for _ in range(data[\"length\"]):\n        id += random.choice(string.ascii_letters)\n    return {\n        \"id\": id\n    }\n\n# Server\n\nif __name__ == \"__main__\":\n    routes = [\n        ('genid', generateRandomID)\n    ]\n    waitress.serve(makeApplication(routes), listen='*:8000')\n```\nDefine custom JSON serializable objects\n```python\nclass Point:\n    \n    def __init__(x, y):\n        self.x = x\n        self.y = y\n\n    @property\n    def _json(self):\n        return [self.x, self.y]\n```\n\n\n## Clean\nValidate and clean the request body.\n\n### Usage\nDecorate your handlers with the `clean.clean` decorator.\n- **`clean`**\n    - **Parameters**\n        - `field` : `Field`  \n        Expected request body scheme.\n    - **Returns**  \n    Validated and cleaned request body.\n    - **Raises**\n        - `exceptions.BadRequestException`  \n        If the request body does not match the provided scheme.\n- **`Field`**\n    - **Constructor**\n        - **Parameters**\n            - `missing` : `Do` or `Default`  \n            What to do when this field is missing.\n            - `error` : `Do` or `Default`  \n            What to do when this field is invalid.\n    - **Methods**\n        - `clean` *(abstract)*  \n            Validate and clean the field.  \n            Derived fields must implement it.\n            - **Parameters**\n                - `value`  \n                Deserialized request body value to clean.\n            - **Returns**  \n            Cleaned value.\n            - **Raises**\n                - `FieldException`  \n                If the value is invalid.\n        - `cleanAndAdd`  \n            Validate and clean the field. \n            - **Parameters**\n                - `present` : `bool`  \n                Whether the field is present or not.\n                - `value`  \n                Deserialized request body value to clean.\n                - `add` : *Callable*  \n                Object (or function) to call if the field is cleaned.\n                    - **Parameters**\n                        - `value`  \n                        Cleaned value.  \n### Examples\nSimple cleaning\n```python\nfrom swjas.clean import clean, Default, IntField, StringField, FloatField, DictField, ListField\n\n@clean(DictField({\n    \"a\": IntField(min=1),\n    \"b\": IntField(min=1)\n}))\ndef sumPositiveIntegers(data):\n    return {\n        \"sum\": data[\"a\"] + data[\"b\"]\n    }\n\n@clean(ListField(minLength=1, fields=FloatField()))\ndef floatAverage(data):\n    return sum(data) / len(data)\n\n@clean(DictField({\n    \"username\": StringField(minLength=5, maxLength=20, regex=r\"[A-Za-z0-9]+\"),\n    \"password\": StringField(minLength=8, maxLength=16, regex=r\"[A-Za-z0-9]+\"),\n    \"age\": IntField(min=18, max=150, missing=Default(None)),\n    \"fullName\": StringField(minLength=1, maxLength=128, missing=Default(None))\n}))\ndef printMe(data):\n    print(data)\n    return {\n        \"success\": True\n    }\n```\nCustom field\n```python\nfrom swjas.clean import TypeField, FieldException, Do\n\nclass EvenNumberField(TypeField):\n\n    def __init__(self, missing=Do.RAISE, error=Do.RAISE):\n        super().__init__(int, missing=missing, error=error)\n\n    def clean(self, value):\n        value = super().clean(value)\n        if value % 2 != 0:\n            raise FieldException(\"Odd number\")\n        return value\n```\n\n\n## Exceptions\n\n### Usage\nAny uncatched `exceptions.HttpException` will be serialized and added to the response body and will set the corresponding Http response status.  \nAny `exception.PrintableException` cause set with the `raise ... from` syntax will be added to the response body too.\n\n### Examples\nRaise an `HttpException`\n```python\nfrom swjas.exceptions import AuthorizationException, NotFoundException\nif not authenticated:\n    raise AuthorizationException(message=\"Requested object requires authentication\")\nelif not exists:\n    raise NotFoundException(message=\"Requested object does not exist\")\n```\nRaise an `HttpException` with cause\n```python\ntry:\n    validateRequest(data)\nexcept Exception as e:\n    from swjas.exceptions import BadRequestException\n    raise BadRequestException(message=\"Error while validating the request\") from e\n```\nCreate an `HttpException` on the fly\n```python\nfrom swjas.exceptions import HttpException\nraise HttpException.build(410)\n```\nDefine an `HttpException`\n```python\nfrom swjas.exceptions import HttpException\n\nclass GoneException(HttpException):\n    statusCode = 410\n```\n\n\n## Client\nSend requests.\n\n### Usage\nRun `python -m swjas.client -h` from command line or call `client.request` or `client.service` functions.\n\n### Examples\nSend a request providing JSON body via command line and save result to JSON file\n```\n\u003e\u003e\u003e python -m swjas.client //localhost:8080/signup --outputstatus --indent 4 \u003e response.json\n{\n    \"username\": \"Francesco\",\n    \"password\": \"12345\"  \n}\n^Z\n```\nSend a request providing JSON body via file and print result to console\n```\n\u003e\u003e\u003e python -m swjas.client //localhost:8080/signup --if request.json\n{\n    \"result\": \"success\"\n}\n```\nSend a request via script\n```python\nfrom swjas.client import HttpException, RequestException, request\n\ndata = {\n    \"username\": \"Francesco\",\n    \"password\": \"12345\"\n}\n\ntry:\n    res = request(\"//localhost:8080/signup\", data)\nexcept HttpException as e:\n    print(f\"{e.statusCode}: {e.statusMessage}\\n{e.responseBody}\")\nexcept RequestException as e:\n    print(f\"Request failed: {e}\")\n```\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffrancescozoccheddu%2Fswjas","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ffrancescozoccheddu%2Fswjas","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffrancescozoccheddu%2Fswjas/lists"}