typed-sentinels
Statically-typed sentinel objects with singleton qualities.
Installation
pip install typed-sentinels
Quick Start
Sentinelinstances are useful for creating unique, type-annotated placeholders, typically used when a default value other thanNoneis desirable. Only a single instance ofSentinelmay exist for a given type.
from typed_sentinels import Sentinel
# Annotate with the type the sentinel should appear to be to the type-checker
SENTINEL_STR: str = Sentinel(str)
def process_data(value: str = SENTINEL_STR) -> str:
# Sentinels are always falsy
if not value:
return 'No value provided'
return f'Processing: {value}'
# Type-safe usage
result = process_data() # "No value provided"
result = process_data('demo123') # "Processing: demo123"
- The
Sentinelclass is particularly well-suited for use with types requiring parameters which are only available at runtime, where creating a default instance of the type may not be possible in advance, but the structural contract of the type is otherwise guaranteed to be fulfilled once present.
from typed_sentinels import Sentinel
class Custom:
@property
def value(self) -> str:
return self._value
def __init__(self, required: str, /) -> None:
self._value = required
# Appears to the type-checker as an instance of `Custom`
CUSTOM: Custom = Sentinel(Custom)
def func(c: Custom = CUSTOM) -> str:
if c is not CUSTOM:
return c.value
return 'c was not provided'
Sentinelinstances have singleton qualities, but remain distinct as specific to the type they represent:
S1 = Sentinel(dict[str, Any])
S2 = Sentinel(dict[str, Any])
S3 = Sentinel(dict[str, bytes])
assert S1 is S2 # True
assert S2 is not S3 # True
- In the simplest form, supposing you don't want or need a distinct instance for different types, you could use the
Sentinelwithout parameterization or arguments, and the type-checker will still be happy:
class Custom:
def __init__(self, arg1: str, arg2: int, arg3: bool) -> None: ...
# This appears to the type-checker as an actual instance of Custom
CUSTOM: Custom = Sentinel()
reveal_type(CUSTOM) # Runtime type is 'Sentinel'
Metadata
Release files for typed-sentinels 1.1.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| typed_sentinels-1.1.1.tar.gz | 5.6 kB | With provenance | Details for typed_sentinels-1.1.1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| typed_sentinels-1.1.1-py3-none-any.whl | Python 3 | none | any | Details for typed_sentinels-1.1.1-py3-none-any.whl |
Total release size: 12.9 kB
Release files / typed_sentinels-1.1.1.tar.gz
| Download URL | typed_sentinels-1.1.1.tar.gz |
|---|---|
| Size | 5.6 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
f7f93e8afee66ccd41ce9d8ec1e12cef0fcbd4eafefebec7767ac33c7f7ec611
|
|
BLAKE2b-256 checksum How to use checksums |
d80918e3901c675429c5f0d34ea4d949142010594fafef2dad41d1b435fc251d
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.13
|
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.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Jun 13, 2026.
Transparency logRelease files / typed_sentinels-1.1.1-py3-none-any.whl
| Download URL | typed_sentinels-1.1.1-py3-none-any.whl |
|---|---|
| Size | 7.3 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
11b71aa2a75b3523e4f8505cd00e0ba0be437d87d4f2f733c1a9cb3116de9ceb
|
|
BLAKE2b-256 checksum How to use checksums |
28b94c693c3257982aea39785ba6abef86ad992c7e33ebb3ebd2a3a807240cdc
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.13
|
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.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Jun 13, 2026.
Transparency logSecurity for typed-sentinels 1.1.1
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.
Full provenance
All 2 files in this release have been uploaded with provenance metadata.
Attestation for typed_sentinels-1.1.1.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Jun 13, 2026.
Transparency logA 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.