{"id":19280680,"url":"https://github.com/abeltavares/pysertive","last_synced_at":"2025-04-22T01:30:44.742Z","repository":{"id":240048364,"uuid":"800707514","full_name":"abeltavares/pysertive","owner":"abeltavares","description":"✔️ Assertive python design by contract toolkit for software validation. Simplify preconditions, postconditions, and invariants with easy-to-use decorators.","archived":false,"fork":false,"pushed_at":"2024-05-21T19:53:43.000Z","size":101,"stargazers_count":5,"open_issues_count":7,"forks_count":1,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-04-13T20:08:24.502Z","etag":null,"topics":["assertions","code-maintainability","code-validation","dbc","design-by-contract","error-checking","postconditions","preconditions","pypi-package","python","python-decorators","python-library","software-quality"],"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/abeltavares.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":".github/CODEOWNERS","security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-05-14T20:59:09.000Z","updated_at":"2024-10-14T05:01:07.000Z","dependencies_parsed_at":"2024-05-20T21:30:44.785Z","dependency_job_id":"12d100d5-7c0e-437c-b02a-ae25aba435bf","html_url":"https://github.com/abeltavares/pysertive","commit_stats":null,"previous_names":["abeltavares/pysertive"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/abeltavares%2Fpysertive","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/abeltavares%2Fpysertive/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/abeltavares%2Fpysertive/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/abeltavares%2Fpysertive/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/abeltavares","download_url":"https://codeload.github.com/abeltavares/pysertive/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":250161915,"owners_count":21385007,"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":["assertions","code-maintainability","code-validation","dbc","design-by-contract","error-checking","postconditions","preconditions","pypi-package","python","python-decorators","python-library","software-quality"],"created_at":"2024-11-09T21:19:37.375Z","updated_at":"2025-04-22T01:30:44.496Z","avatar_url":"https://github.com/abeltavares.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"Pysertive ✔️\n=========\n\n\u003cp align=\"center\"\u003e\n    \u003cimg src=\"assets/pysertive.png\" alt=\"Pysertive Logo\" width=\"200\" height=\"200\"\u003e\n\u003c/p\u003e\n\n\u003cp align=\"center\"\u003e\n    \u003ca href=\"https://github.com/abeltavares/pysertive/releases\"\u003e\n        \u003cimg src=\"https://img.shields.io/github/v/release/abeltavares/pysertive.svg\" alt=\"Latest release\"\u003e\n    \u003c/a\u003e\n    \u003ca href=\"https://github.com/abeltavares/pysertive/actions/workflows/unit-tests.yml\"\u003e\n        \u003cimg src=\"https://github.com/abeltavares/pysertive/actions/workflows/unit-tests.yml/badge.svg\" alt=\"build status (GitHub Actions)\"\u003e\n    \u003c/a\u003e\n    \u003c!-- COVERAGE_BADGE_URL --\u003e\n    \u003ca href=\"https://img.shields.io/badge/coverage-100%25-green\"\u003e\n        \u003cimg src=\"https://img.shields.io/badge/coverage-100%25-green\" alt=\"code coverage\"\u003e\n    \u003c/a\u003e\n    \u003c!-- END_COVERAGE_BADGE_URL --\u003e\n    \u003ca href=\"https://pypi.python.org/pypi/pysertive\"\u003e\n        \u003cimg src=\"https://img.shields.io/pypi/v/reader.svg\" alt=\"PyPI status\"\u003e\n    \u003c/a\u003e\n    \u003ca href=\"http://mypy-lang.org/\"\u003e\n        \u003cimg src=\"http://www.mypy-lang.org/static/mypy_badge.svg\" alt=\"checked with mypy\"\u003e\n    \u003c/a\u003e\n    \u003ca href=\"https://github.com/pre-commit/pre-commit\"\u003e\n        \u003cimg src=\"https://img.shields.io/badge/pre--commit-enabled-brightgreen?logo=pre-commit\u0026logoColor=white\" alt=\"pre-commit enabled\"\u003e\n    \u003c/a\u003e\n    \u003ca href=\"https://github.com/psf/black\"\u003e\n        \u003cimg src=\"https://img.shields.io/badge/code%20style-black-000000.svg\" alt=\"code style: black\"\u003e\n    \u003c/a\u003e\n\u003c/p\u003e\n\n\u003cbr\u003e\n\n\u003cdiv align=\"center\"\u003e\n\n**Pysertive**: Assertive Python Design by Contract (DbC) Toolkit\n\n\u003c/div\u003e\n\nWhat is it?\n--------\n\nPysertive is a Python library that provides decorators for implementing Design by Contract (DbC) principles. It simplifies enforcing preconditions, postconditions, and invariants in your code. \nPysertive aims to be a powerful tool for ensuring code behavior and constraints, promoting secure, maintainable, and robust software development in Python.\n## Table of Contents\n\n-   [Features](#features)\n-   [Where to get it?](#where-to-get-it)\n-  [Quick Start](#quick-start)\n- [Usage](#usage)\n- [Why Pysertive?](#why-pysertive)\n- [Examples](#examples)\n- [Contributing](#contributing)\n- [License](#license)\n\n🌟 Features\n--------\nThe things that Pysertive does well:\n\n-   Preconditions: Ensure that function inputs meet defined criteria before execution.\n-   Postconditions: Validate that the function outputs conform to expected conditions after execution.\n-   Invariants: Guarantee that certain conditions remain true throughout the lifecycle of class instances.\n\nPysertive is designed with simplicity and flexibility in mind, allowing you to easily integrate rigorous contract checks into your Python code, which helps in debugging and maintaining complex systems.\n\n📦 Where to get it?\n------------\n\nTo install Pysertive, simply use pip:\n\n```bash\npip install pysertive\n```\n\n🚀 Quick Start\n-----------\n\nHere's how to quickly get started with Pysertive:\n\n```python\nfrom pysertive import pre_condition, post_condition, invariant\n\n@pre_condition(lambda x: x \u003e 0, exception_type=ValueError, message=\"Input must be positive\")\ndef sqrt(x):\n    return x ** 0.5\n\n@post_condition(lambda result: result != None, exception_type=AssertionError, message=\"Result cannot be None\")\ndef fetch_data():\n    return {\"data\": \"Here is your data\"}\n\n@invariant(lambda self: self.balance \u003e= 0, exception_type=RuntimeError, message=\"Insufficient funds\")\nclass BankAccount:\n    def __init__(self, balance):\n        self.balance = balance\n\n    def deposit(self, amount):\n        self.balance += amount\n\n    def withdraw(self, amount):\n        self.balance -= amount  # No need to manually check for negative balance\n```\n\n🔧 Usage\n-----\n\n### Using Preconditions\n\nEnsure inputs to your functions are valid:\n\n```python\n@pre_condition(lambda age: age \u003e= 18, exception_type=ValueError, message=\"Must be 18 or older\")\ndef sign_contract(age):\n    print(f\"Contract signed by individual aged {age}\")\n```\n\n### Using Postconditions\n\nValidate outputs after your functions execute:\n\n```python\n@post_condition(lambda result: result \u003e 0, exception_type=AssertionError, message=\"Profit must be positive\")\ndef calculate_profit(revenue, costs):\n    return revenue - costs\n```\n\n### Using Invariants\n\nEnforce class states remain consistent:\n\n```python\n@invariant(lambda self: self.inventory_count \u003e= 0, exception_type=RuntimeError, message=\"Inventory count cannot be negative\")\nclass Warehouse:\n    def __init__(self, inventory_count):\n        self.inventory_count = inventory_count\n\n    def add_stock(self, number):\n        self.inventory_count += number\n\n    def remove_stock(self, number):\n        self.inventory_count -= number\n```\n\n❓ Why Pysertive?\n--------------\n\n-   Reliability: Enforce rules consistently across your application.\n-   Maintainability: Easier to manage and update code with clear contractual obligations.\n-   Security: Prevents unexpected behaviors by strictly checking function inputs and outputs.\n\n## 📚 Examples\n\nFor more detailed examples of how to use Pysertive, check out the `examples.py` file in the repository. This file contains examples of how to use preconditions, postconditions, and invariants in your Python code.\n\n🤝 Contributing\n------------\n\nContributions are welcome! If you'd like to contribute, please check out the [Contributing Guide](CONTRIBUTING.md), and feel free to open an issue or a pull request.\n\n📜 License\n-------\n\nPysertive is released under the MIT License. See the [License](LICENSE.txt) file for more details.\n\n\u003chr\u003e\n\n[Go to Top](#table-of-contents)","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fabeltavares%2Fpysertive","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fabeltavares%2Fpysertive","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fabeltavares%2Fpysertive/lists"}