Metadata-Version: 2.4
Name: identity-fingerprint
Version: 0.4.0
Summary: Deterministic Customer Identity (CID) generation for Customer 360 and MDM.
Author-email: Melbin Martin <melbinmartinmm@gmail.com>
License: MIT License
        
        Copyright (c) 2026 Melbin Martin
        
        Permission is hereby granted, free of charge, to any person obtaining a copy
        of this software and associated documentation files (the "Software"), to deal
        in the Software without restriction, including without limitation the rights
        to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
        copies of the Software, and to permit persons to whom the Software is
        furnished to do so, subject to the following conditions:
        
        The above copyright notice and this permission notice shall be included in all
        copies or substantial portions of the Software.
        
        THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
        IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
        FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
        AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
        LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
        OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
        SOFTWARE.
        
Keywords: cid,customer-360,mdm,identity,hashing,sha256
Classifier: Development Status :: 4 - Beta
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: MIT License
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.9
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Topic :: Software Development :: Libraries :: Python Modules
Classifier: Typing :: Typed
Requires-Python: >=3.9
Description-Content-Type: text/markdown
License-File: LICENSE
Provides-Extra: pandas
Requires-Dist: pandas>=1.5; extra == "pandas"
Provides-Extra: dev
Requires-Dist: pytest>=7.4; extra == "dev"
Requires-Dist: pytest-cov>=4.1; extra == "dev"
Requires-Dist: ruff>=0.4; extra == "dev"
Requires-Dist: mypy>=1.8; extra == "dev"
Requires-Dist: build>=1.0; extra == "dev"
Requires-Dist: twine>=5.0; extra == "dev"
Requires-Dist: pandas>=1.5; extra == "dev"
Dynamic: license-file

# 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, null handling, phone normalisation)
- Phone normalisation (keep last 10 digits; rejected only if fewer than 10 digits)
- 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

```bash
pip install identity-fingerprint
```

With optional pandas support:

```bash
pip install "identity-fingerprint[pandas]"
```

From source (editable, with dev tools):

```bash
pip install -e ".[dev]"
```

Requires **Python 3.9+**.

---

## Quick start

```python
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:

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

### Public API

```python
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

| Field  | Rules |
|--------|-------|
| Name   | trim whitespace, lowercase |
| Email  | trim, lowercase, map `null` / `none` / `nan` → `""` |
| Phone  | strip spaces/dots/dashes/`+`, digits only, keep last 10 digits, reject only if fewer than 10 digits |

The canonical identity string is concatenated as:

```
cleaned_first_name + cleaned_last_name + cleaned_phone + cleaned_email
```

then hashed with SHA-256.

---

## Error handling

```python
from identity_fingerprint import generate_cid
from identity_fingerprint.exceptions import InvalidPhoneNumberError, ValidationError

try:
    generate_cid("John", "Smith", phone="12345")   # too few digits
except InvalidPhoneNumberError as exc:
    print("bad phone:", exc)

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

Enable logging to see cleaning / hashing activity:

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

---

## Pandas integration

```python
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

```bash
pip install build
python -m build
```

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

```bash
pip install twine
twine check dist/*
```

---

## Publishing

### Public PyPI

Manual (token-based):

```bash
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:

```bash
twine upload --repository testpypi dist/*
```

### AWS CodeArtifact

```bash
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:

```bash
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):

```ini
[distutils]
index-servers = azure

[azure]
repository = https://pkgs.dev.azure.com/<org>/<project>/_packaging/<feed>/pypi/upload/
username = <org>
password = <personal-access-token>
```

```bash
pip install twine keyring artifacts-keyring
python -m build
twine upload --repository azure dist/*
```

Install:

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

---

## Versioning strategy

This project follows **[Semantic Versioning](https://semver.org/) `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

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

---

## License

MIT — see [LICENSE](LICENSE).
