{"id":13801029,"url":"https://github.com/pynamodb/pynamodb-mypy","last_synced_at":"2025-04-09T20:43:05.247Z","repository":{"id":62581977,"uuid":"264966794","full_name":"pynamodb/pynamodb-mypy","owner":"pynamodb","description":"mypy plugin for PynamoDB","archived":false,"fork":false,"pushed_at":"2022-10-21T03:25:10.000Z","size":42,"stargazers_count":4,"open_issues_count":1,"forks_count":1,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-31T09:14:13.126Z","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":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/pynamodb.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-05-18T14:35:11.000Z","updated_at":"2024-01-03T14:17:02.000Z","dependencies_parsed_at":"2022-11-03T21:56:02.043Z","dependency_job_id":null,"html_url":"https://github.com/pynamodb/pynamodb-mypy","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pynamodb%2Fpynamodb-mypy","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pynamodb%2Fpynamodb-mypy/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pynamodb%2Fpynamodb-mypy/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pynamodb%2Fpynamodb-mypy/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/pynamodb","download_url":"https://codeload.github.com/pynamodb/pynamodb-mypy/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248032349,"owners_count":21036576,"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-04T00:01:18.750Z","updated_at":"2025-04-09T20:43:05.223Z","avatar_url":"https://github.com/pynamodb.png","language":"Python","funding_links":[],"categories":["Tools"],"sub_categories":["Mypy plugins"],"readme":"# pynamodb-mypy\n\nA plugin for mypy which gives it deeper understanding of PynamoDB (beyond what's possible through type stubs).\n\n# Usage\n\nAdd it to the `plugins` option of the `[mypy]` section in your mypy.ini:\n```ini\n[mypy]\nplugins = pynamodb_mypy\n```\n\n# Nullable attributes\n\nWhen declaring attributes with `null=True`, the value types would become optional. For example:\n```py\nfrom pynamodb.attributes import UnicodeAttribute\nfrom pynamodb.models import Model\n\nclass MyModel(Model):\n  my_key = UnicodeAttribute()\n  my_value = UnicodeAttribute(null=True)\n\n...\nmy_model = MyModel.get('key')\nif my_model.my_value.lower() == 'foo':  # error: Item \"None\" of \"Optional[str]\" has no attribute \"lower\"\n   print(\"Value is foo\")\n```\nwould have to be changed to, e.g.:\n```py\nif my_model.my_value and my_model.my_value.lower() == 'foo':\n   print(\"Value is foo\")\n```\n\n# Typed model initializers\n\nWhen declaring models, the `__init__` method would be typed to accept only the attributes declared in the model. For example:\n```py\nfrom pynamodb.models import Model\nfrom pynamodb.attributes import NumberAttribute\nfrom pynamodb.attributes import UnicodeAttribute\n\nclass MyModel(Model):\n  my_key = UnicodeAttribute(hash_key=True)\n  my_value = NumberAttribute(null=True)\n\n# Existing attributes would be enforced:\n_ = MyModel(my_key='key', my_value=42, my_other_value='other_value')  # error: Unexpected keyword argument \"my_other_value\" for \"MyModel\"\n\n# Typing would be enforced:\n_ = MyModel(my_key='key', my_value='42')  # error: Argument 2 to \"MyModel\" has incompatible type \"str\"; expected \"Optional[int]\"\n\n# Nullability will be enforced::\n_ = MyModel(my_key='key', my_value=None)\n_ = MyModel(my_key=None, my_value=None)  # error: Argument \"my_key\" to \"MyModel\" has incompatible type \"None\"; expected \"str\"\n\n# The hash key and range key can also be passed as positional arguments:\n_ = MyModel('key')\n_ = MyModel(42)  # error: Argument 1 to \"MyModel\" has incompatible type \"int\"; expected \"str\"\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpynamodb%2Fpynamodb-mypy","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpynamodb%2Fpynamodb-mypy","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpynamodb%2Fpynamodb-mypy/lists"}