Skip to main content

identity-fingerprint

Deterministic Customer Identity (CID) generation for Customer 360 and Master Data Management (MDM) use cases.

Multiple source systems rarely store customer data the same way: casing, whitespace, phone formatting and null tokens all differ. identity-fingerprint standardises the inputs, then produces a stable SHA-256 fingerprint so the same real-world customer resolves to the same CID everywhere.


Features

  • Deterministic SHA-256 CID from first name + last name + phone + email
  • Automatic input standardisation (trim, lowercase, name punctuation removal, phone normalisation)
  • Phone normalisation (last 10 digits, valid Indian mobiles only; anything else is ignored)
  • Simple public API: a single generate_cid(...) call
  • Type hints, docstrings, logging, custom exceptions
  • Optional pandas integration for bulk DataFrame processing
  • Zero required runtime dependencies

Installation

pip install identity-fingerprint

With optional pandas support:

pip install "identity-fingerprint[pandas]"

From source (editable, with dev tools):

pip install -e ".[dev]"

Requires Python 3.9+.


Quick start

from identity_fingerprint import generate_cid

cid = generate_cid(
    first_name="John",
    last_name="Smith",
    email="john@gmail.com",
    phone="9876543210",
)
print(cid)  # 64-character SHA-256 hex digest

Differently formatted records for the same customer produce the same CID:

a = generate_cid("John", "Smith", "john@gmail.com", "9876543210")
b = generate_cid(" john ", " SMITH ", "JOHN@GMAIL.COM", "+91-9876543210")
assert a == b

Public API

generate_cid(
    first_name: str,
    last_name: str,
    email: str = "",
    phone: str = "",
) -> str

Also exported: clean_name, clean_email, clean_phone, sha256_hash, and the exceptions IdentityFingerprintError, ValidationError, InvalidPhoneNumberError.


Cleaning / matching rules

Rules as of v0.5.0:

Field Rules Examples
Name trim, lowercase, remove every character that is not a letter or digit (spaces, dots, hyphens, apostrophes, non-latin letters). Digits are kept. "Rakesh Kumar" → rakeshkumar, "O'Brien-Smith" → obriensmith, "Adult 1" → adult1
Email trim, lowercase. None → "" " John@Gmail.com " → john@gmail.com
Phone remove every non-digit, keep the last 10 digits, accept only a valid Indian mobile (10 digits starting 6–9). Anything else → "", so the CID falls back to name + email. Never raises. "+91-9876543210" → 9876543210, "12345" → "", "12025550143" → ""

generate_cid raises ValidationError only when both names are empty after cleaning. email and phone are optional.

The canonical identity string is concatenated as:

cleaned_first_name + cleaned_last_name + cleaned_phone + cleaned_email

then hashed with SHA-256.


Error handling

from identity_fingerprint import generate_cid
from identity_fingerprint.exceptions import ValidationError

# An invalid phone does not raise: it is ignored and the CID uses name + email.
assert generate_cid("John", "Smith", "john@gmail.com", phone="12345") == \
       generate_cid("John", "Smith", "john@gmail.com")

try:
    generate_cid("", "", email="x@y.com")           # no name
except ValidationError as exc:
    print("validation:", exc)

Version history

Version Change Existing CIDs
0.5.0 Names containing digits are accepted (digits kept) instead of raising ValidationError. Unchanged. Names without digits give the same CID as 0.4.0.
0.4.0 Name: remove non-letters, reject digits. Phone: valid Indian mobiles only, invalid → "" instead of raising. Changed from 0.2.1.
0.2.1 Name: trim + lowercase. Phone: last 10 characters, raise if fewer than 10.

Enable logging to see cleaning / hashing activity:

import logging
logging.basicConfig(level=logging.DEBUG)

Pandas integration

import pandas as pd
from identity_fingerprint import generate_cid

df = pd.DataFrame({
    "first_name": ["John", "Jane"],
    "last_name":  ["Smith", "Doe"],
    "email":      ["john@gmail.com", "jane@doe.com"],
    "phone":      ["+91-9876543210", "9123456780"],
})

# Direct apply
df["CID"] = df.apply(
    lambda r: generate_cid(r["first_name"], r["last_name"], r["email"], r["phone"]),
    axis=1,
)

# Or use the helper (install the [pandas] extra)
from identity_fingerprint.pandas_integration import add_cid_column
df = add_cid_column(df, errors="coerce")  # bad rows -> None instead of raising

Building the package

pip install build
python -m build

This produces dist/identity_fingerprint-<version>-py3-none-any.whl and a source tarball. Validate metadata before publishing:

pip install twine
twine check dist/*

Publishing

Public PyPI

Manual (token-based):

python -m build
twine upload dist/*
# username: __token__   password: <your PyPI API token>

Recommended: Trusted Publishing (OIDC) via GitHub Actions — see .github/workflows/release.yml. No tokens stored; configure a publisher at https://pypi.org/manage/account/publishing/. Test first against TestPyPI:

twine upload --repository testpypi dist/*

AWS CodeArtifact

aws codeartifact login \
  --tool twine \
  --domain my-domain \
  --domain-owner 111122223333 \
  --repository my-repo

python -m build
twine upload --repository codeartifact dist/*

Install from CodeArtifact:

aws codeartifact login --tool pip --domain my-domain \
  --domain-owner 111122223333 --repository my-repo
pip install identity-fingerprint

Azure Artifacts

Create ~/.pypirc (or use az artifacts + a PAT):

[distutils]
index-servers = azure

[azure]
repository = https://pkgs.dev.azure.com/<org>/<project>/_packaging/<feed>/pypi/upload/
username = <org>
password = <personal-access-token>
pip install twine keyring artifacts-keyring
python -m build
twine upload --repository azure dist/*

Install:

pip install identity-fingerprint \
  --index-url https://pkgs.dev.azure.com/<org>/<project>/_packaging/<feed>/pypi/simple/

Versioning strategy

This project follows Semantic Versioning MAJOR.MINOR.PATCH:

  • MAJOR — incompatible API changes, or any change to cleaning rules / concatenation order that alters produced CIDs (CID stability is part of the public contract).
  • MINOR — backward-compatible functionality (new helpers, new optional args).
  • PATCH — backward-compatible bug fixes and docs.

The version is defined in two places kept in sync: pyproject.toml and __version__ in src/identity_fingerprint/__init__.py.

Automated release flow

  1. Bump the version in pyproject.toml and __init__.py.
  2. Commit and tag: git tag v0.1.0 && git push --tags.
  3. The release.yml workflow builds the sdist + wheel and publishes to PyPI via OIDC trusted publishing on the tag push (or on a published GitHub Release).
  4. CI (ci.yml) runs lint, type-check and tests across Python 3.9-3.12 on every push and PR to main.

Development

pip install -e ".[dev]"
pytest --cov=identity_fingerprint
ruff check .
mypy

License

MIT — see LICENSE.

Metadata

Release files for identity-fingerprint 0.5.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 identity-fingerprint 0.5.0
File Size Uploaded Provenance Actions
identity_fingerprint-0.5.0.tar.gz 15.3 kB Without provenance Details for identity_fingerprint-0.5.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for identity-fingerprint 0.5.0
File Interpreter ABI Platform Actions
identity_fingerprint-0.5.0-py3-none-any.whl Python 3 none any Details for identity_fingerprint-0.5.0-py3-none-any.whl

Total release size: 28.2 kB

Release files / identity_fingerprint-0.5.0.tar.gz

Download URL identity_fingerprint-0.5.0.tar.gz
Size 15.3 kB
Tags Source
SHA-256 checksum
How to use checksums
b8dd6c4b2cbb9c4be0897cd87ca0e11cbe14e928cb4f93a972815a5c711b9d03
BLAKE2b-256 checksum
How to use checksums
0d7e5aefd4ff185770b487fce848bc3c201686f387435eb48ee33c62f6ccdc41
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.11.1

Release files / identity_fingerprint-0.5.0-py3-none-any.whl

Download URL identity_fingerprint-0.5.0-py3-none-any.whl
Size 12.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
7ffbadcc38d9e181afe4cb79373ffd247eb8b40936ccddb5fa29f6c97831bc06
BLAKE2b-256 checksum
How to use checksums
b74a189105a880fd3d2b17046c2833fa9404e31b429437c42a499f39aeb6b4d3
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.11.1

Security for identity-fingerprint 0.5.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