Skip to main content

pynamodb-mypy

A plugin for mypy which gives it deeper understanding of PynamoDB (beyond what's possible through type stubs).

Usage

Add it to the plugins option of the [mypy] section in your mypy.ini:

[mypy]
plugins = pynamodb_mypy

Nullable attributes

When declaring attributes with null=True, the value types would become optional. For example:

from pynamodb.attributes import UnicodeAttribute
from pynamodb.models import Model

class MyModel(Model):
  my_key = UnicodeAttribute()
  my_value = UnicodeAttribute(null=True)

...
my_model = MyModel.get('key')
if my_model.my_value.lower() == 'foo':  # error: Item "None" of "Optional[str]" has no attribute "lower"
   print("Value is foo")

would have to be changed to, e.g.:

if my_model.my_value and my_model.my_value.lower() == 'foo':
   print("Value is foo")

Typed model initializers

When declaring models, the __init__ method would be typed to accept only the attributes declared in the model. For example:

from pynamodb.models import Model
from pynamodb.attributes import NumberAttribute
from pynamodb.attributes import UnicodeAttribute

class MyModel(Model):
  my_key = UnicodeAttribute(hash_key=True)
  my_value = NumberAttribute(null=True)

# Existing attributes would be enforced:
_ = MyModel(my_key='key', my_value=42, my_other_value='other_value')  # error: Unexpected keyword argument "my_other_value" for "MyModel"

# Typing would be enforced:
_ = MyModel(my_key='key', my_value='42')  # error: Argument 2 to "MyModel" has incompatible type "str"; expected "Optional[int]"

# Nullability will be enforced::
_ = MyModel(my_key='key', my_value=None)
_ = MyModel(my_key=None, my_value=None)  # error: Argument "my_key" to "MyModel" has incompatible type "None"; expected "str"

# The hash key and range key can also be passed as positional arguments:
_ = MyModel('key')
_ = MyModel(42)  # error: Argument 1 to "MyModel" has incompatible type "int"; expected "str"

Metadata

Release files for pynamodb-mypy 0.1.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pynamodb-mypy 0.1.2
File Size Uploaded Provenance Actions
pynamodb-mypy-0.1.2.tar.gz 9.3 kB Without provenance Details for pynamodb-mypy-0.1.2.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for pynamodb-mypy 0.1.2
File Interpreter ABI Platform Actions
pynamodb_mypy-0.1.2-py3-none-any.whl Python 3 none any Details for pynamodb_mypy-0.1.2-py3-none-any.whl

Total release size: 19.2 kB

Release files / pynamodb-mypy-0.1.2.tar.gz

Download URL pynamodb-mypy-0.1.2.tar.gz
Size 9.3 kB
Tags Source
SHA-256 checksum
How to use checksums
fb8fcaf965d3c85464ac85203625b11b4faa2dd3f150d6ddb993df1c26c1bf0d
BLAKE2b-256 checksum
How to use checksums
76b90639e096a44fa187f621f0821161898f72718cc9c3d2c4c37b3d236523c7
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.1 CPython/3.9.15

Release files / pynamodb_mypy-0.1.2-py3-none-any.whl

Download URL pynamodb_mypy-0.1.2-py3-none-any.whl
Size 9.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
a7eba5ab3a50a8206f42b476807fd0ea18723aad1ef94dce9318e3394f3cbcb6
BLAKE2b-256 checksum
How to use checksums
5ec34855b1ab1e17344f9a25af9fc3fb2ca915fa11b56c63bd161094ae7863e0
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.1 CPython/3.9.15

Security for pynamodb-mypy 0.1.2

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page