Skip to main content

Overview

The sentinels module is a small utility providing the Sentinel class, along with useful instances.

What are Sentinels?

Sentinels are objects with special meanings. They can be thought of as singletons, but they service the need of having 'special' values in your code, that have special meanings (see example below).

Why Do I Need Sentinels?

Let's take NOTHING for example. This sentinel is automatically provided with the sentinels import:

>>> from sentinels import NOTHING

Let's say you're writing a wrapper around a Python dictionary, which supports a special kind of method, get_default_or_raise. This method behaves like get, but when it does not receive a default and the key does not exist, it raises a KeyError. How would you implement such a thing? The naive method is this:

>>> class MyDict(dict):
...     def get_default_or_raise(self, key, default=None):
...         if key not in self and default is None:
...             raise KeyError(key)
...         return self.get(key, default)

Or even this:

>>> class MyDict(dict):
...     def get_default_or_raise(self, key, default=None):
...         returned = self.get(key, default)
...         if returned is None:
...             raise KeyError(key)
...         return returned

But the problem with the above two pieces of code is the same -- when writing a general utility class, we don't know how it will be used later on. More importantly, None might be a perfectly valid dictionary value!

This is where NOTHING comes in handy:

>>> class MyDict(dict):
...     def get_default_or_raise(self, key, default=NOTHING):
...         returned = self.get(key, default)
...         if returned is NOTHING:
...             raise KeyError(key)
...         return returned

And Tada!

Semantics

Sentinels are always equal to themselves:

>>> NOTHING == NOTHING
True

But never to another object:

>>> from sentinels import Sentinel
>>> NOTHING == 2
False
>>> NOTHING == "NOTHING"
False

Copying sentinels returns the same object:

>>> import copy
>>> copy.deepcopy(NOTHING) is NOTHING
True

And of course also pickling/unpickling:

>>> import pickle
>>> NOTHING is pickle.loads(pickle.dumps(NOTHING))
True

Release files for 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)

Source distribution for sentinels 1.1.1
File Size Uploaded
sentinels-1.1.1.tar.gz 4.4 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for sentinels 1.1.1
File Interpreter ABI Platform
sentinels-1.1.1-py3-none-any.whl Python 3 none any Details

Total release size: 8.1 kB

Release files / sentinels-1.1.1.tar.gz

Download URL sentinels-1.1.1.tar.gz
Size 4.4 kB
Tags Source
SHA-256 checksum
How to use checksums
3c2f64f754187c19e0a1a029b148b74cf58dd12ec27b4e19c0e5d6e22b5a9a86
BLAKE2b-256 checksum
How to use checksums
6f9b07195878aa25fe6ed209ec74bc55ae3e3d263b60a489c6e73fdca3c8fe05
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.12.9

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 Aug 12, 2025.

Transparency log

Release files / sentinels-1.1.1-py3-none-any.whl

Download URL sentinels-1.1.1-py3-none-any.whl
Size 3.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
835d3b28f3b47f5284afa4bf2db6e00f2dc5f80f9923d4b7e7aeeeccf6146a11
BLAKE2b-256 checksum
How to use checksums
4965dea992c6a97074f6d8ff9eab34741298cac2ce23e2b6c74fb7d08afdf85c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.12.9

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 Aug 12, 2025.

Transparency log

Release history Release notifications | RSS feed

This release

1.1.1 This release

2 release files

1.1.0

2 release files

1.0.0

1 release file

0.0.6

1 release file

0.0.5

1 release file

0.0.4

1 release file

0.0.3

1 release file

0.0.2

3 release files

0.0.1

1 release file

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