Skip to main content

secret-santaclaus

Secret Santa organiser with MCMC random sampling of arbitrary constraints and email utilities.

build pre-commit PyPI - Version

Usage

secret-santaclaus is a Python package for generating near-uniformly random Secret Santa allocations from a set of participants and a set of arbitrary constraints upon who can be allocated to whom. It also includes a built-in utility for secretly sending emails to participants with their allocated recipients.

This package is published to PyPI for easy installation via pip (or any other package manager), e.g.:

pip install secret-santaclaus

See example.py for a simple walkthrough of using the package to configure a Secret Santa model of participants and constraints, generate a solution by sampling a Markov-chain Monte Carlo (MCMC) method, and email participants their allocations via an SMTP mail server. It also demonstrates how each of these can either be defined directly in the Python API, or loaded to/from YAML files.

Methodology

In Secret Santa, participants are randomly and secretly allocated to give each other a gift. This is not a complicated problem to solve: it's just random selection without replacement. Let's say you wanted to impose arbitrary constraints, however, such as couples not being able to get each other as an allocation (because that would be boring!).

This Python package solves this problem by modelling the set of participants as a directed graph, where every edge in the graph represents a valid allocation. For example, if Alice and Bob are couples, as are Charlie and Dan, and as are Eve and Frank, this model graph, $G_m$, would resemble a complete graph with edges between couples removed (Figure 1).

A valid Secret Santa allocation is therefore a vertex cycle cover on $G_m$. Finding a vertex cycle cover is equivalent to finding a perfect matching on the corresponding factor graph, which we define as a bipartite graph $G_f = (V_L, V_R, E)$ with each node in $G_m$ 'copied' into both sides $V_L$ and $V_R$, and with each edge $(u,v)$ in $G_m$ represented by an edge $(u_L, v_R)$ (Figure 2). A perfect matching can be found in polynomial time, yielding a valid solution (Figures 3 and 4).

model-graph factor-graph
Figure 1: Model graph $G_m$ with no edges between couples. Figure 2: Bipartite factor graph $G_f$.
model-graph-solution factor-graph
Figure 3: A valid solution is a vertex cycle cover on the model graph. Figure 4: A vertex cycle cover on the model graph is a perfect matching on the factor graph.

However, algorithms for finding a perfect matching are generally designed as optimisation methods, usually to find a minimum/maximum weight/cardinality. In this case, we aren't interested in an optimal solution, but in fact want to generate random solutions.

This package implements near-uniformly random sampling of bipartite perfect matchings by a Markov-chain Monte Carlo (MCMC) method given by Jerrum and Sinclair (1989). The solver by default progresses the MCMC state before yielding a solution by at least the mixing time, which is calculated from the size of the problem instance.

Metadata

Release files for secret-santaclaus 1.0.0

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

Source distribution (sdist)

Source distribution for secret-santaclaus 1.0.0
File Size Uploaded Provenance Actions
secret_santaclaus-1.0.0.tar.gz 977.1 kB Without provenance Details for secret_santaclaus-1.0.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for secret-santaclaus 1.0.0
File Interpreter ABI Platform Actions
secret_santaclaus-1.0.0-py3-none-any.whl Python 3 none any Details for secret_santaclaus-1.0.0-py3-none-any.whl

Total release size: 988.8 kB

Release files / secret_santaclaus-1.0.0.tar.gz

Download URL secret_santaclaus-1.0.0.tar.gz
Size 977.1 kB
Tags Source
SHA-256 checksum
How to use checksums
e962dfbede094b883aa50503d4288d6488affcda7a09087265f5447c325357a5
BLAKE2b-256 checksum
How to use checksums
2c78d2e752adc3b940bec2e23d78cf272e94bc4f775bde29afc509d74643d1ee
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.9.14 {"installer":{"name":"uv","version":"0.9.14","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Release files / secret_santaclaus-1.0.0-py3-none-any.whl

Download URL secret_santaclaus-1.0.0-py3-none-any.whl
Size 11.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
23ae11843b619da7df042d25113a9117079efc81c1597eb39cfc8b2d1dbb8a45
BLAKE2b-256 checksum
How to use checksums
2d614d17aa1ff420f6e42f58b3111f0e0ed3dc7e420c4591b97c003460180319
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.9.14 {"installer":{"name":"uv","version":"0.9.14","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Security for secret-santaclaus 1.0.0

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