{"id":18773492,"url":"https://github.com/farfetch/checkarg","last_synced_at":"2025-04-13T09:08:03.318Z","repository":{"id":44921302,"uuid":"279655929","full_name":"Farfetch/checkarg","owner":"Farfetch","description":"Guard clause library for Python projects, to validate arguments on every python function/method.","archived":false,"fork":false,"pushed_at":"2024-01-16T09:30:46.000Z","size":262,"stargazers_count":21,"open_issues_count":11,"forks_count":4,"subscribers_count":6,"default_branch":"master","last_synced_at":"2025-04-13T09:07:54.403Z","etag":null,"topics":["farfetch","guard-clauses","hacktoberfest","python"],"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/Farfetch.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":"SECURITY.md","support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2020-07-14T17:53:34.000Z","updated_at":"2024-02-12T11:09:11.000Z","dependencies_parsed_at":"2024-01-16T11:33:59.362Z","dependency_job_id":"14aac7d5-9cbd-4c44-8d38-1e6802332c3c","html_url":"https://github.com/Farfetch/checkarg","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Farfetch%2Fcheckarg","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Farfetch%2Fcheckarg/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Farfetch%2Fcheckarg/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Farfetch%2Fcheckarg/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Farfetch","download_url":"https://codeload.github.com/Farfetch/checkarg/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248688566,"owners_count":21145766,"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":["farfetch","guard-clauses","hacktoberfest","python"],"created_at":"2024-11-07T19:34:13.374Z","updated_at":"2025-04-13T09:08:03.297Z","avatar_url":"https://github.com/Farfetch.png","language":"Python","readme":"![CheckArg](https://raw.githubusercontent.com/Farfetch/checkarg/master/docs/imgs/CheckArg_complete.png)\n\nGuard clause library for Python projects, to validate arguments on every python function/method.\n\n\n## Installation\nYou can install the latest version of this software from the Python package index (PyPI) as follows:\n\n```bash\npip install --upgrade checkarg\n```\n\n## Usage\n\n### Using CheckArg to validate numbers\nIn the following example we want to guarantee the first argument is a negative number and the second argument has a positive value or zero:\n```python\nimport checkarg.number as Number\n\ndef doSomethingValid(negative_number: int, positive_number: int):\n    Number.is_lower(negative_number, 0)\n    Number.is_greater_or_equals(positive_number, 0)\n\n    return negative_number, positive_number\n```\n\n### Using CheckArg to validate text\nThe following example requires the string of the first argument has some content, if it is None or empty or whith whitespaces, it will rise an exception. The second argument only requires to not be None or an empty message:\n```python\nimport checkarg.text as Text\n\ndef doSomethingValid(title: str, body: str):\n    Text.is_not_whitespace(title)\n    Text.is_not_empty(body)\n\n    return title, body\n```\n\n### Controlling the flow with the exceptions\nWhenever the CheckArg detects something wrong it will raise different exceptions by the context. This is an example controling the flow execution:\n```python\nimport checkarg.none_type as NoneType\nimport checkarg.number as Number\nimport checkarg.text as Text\n\nfrom checkarg.exceptions import ArgumentNoneError, ArgumentError, ArgumentOutOfRangeError\n\n\ndef lookup_name(mapping, key: str, default: int):\n    try:\n        Number.is_greater(default, 0)\n    except ArgumentOutOfRangeError:\n        return None\n\n    try:\n        NoneType.is_not_none(mapping)\n    except ArgumentNoneError:\n        return default\n    \n    try:\n        Text.is_not_empty(key)\n    except (ArgumentError, ArgumentNoneError) as e:\n        return default\n\n    return mapping[key]\n```\n\n\n## Contributing\nRead the [Contributing guidelines](CONTRIBUTING.md)\n\n\n### Disclaimer\nBy sending us your contributions, you are agreeing that your contribution is made subject to the terms of our [Contributor Ownership Statement](https://github.com/Farfetch/.github/blob/master/COS.md)\n\n\n## Maintainers\nList of [Maintainers](MAINTAINERS.md)\n\n\n## License\n[MIT](LICENSE)\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffarfetch%2Fcheckarg","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ffarfetch%2Fcheckarg","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffarfetch%2Fcheckarg/lists"}