Skip to main content

colsemantics

PyPI version Python versions CI License PyPI downloads

Find out what each column of a table means, and which ones hold personal data, without a schema. colsemantics infers the role (identifier, date, money, contact, ...), the business domain, and a privacy recommendation for tabular columns, from names, sampled values, and neighboring columns. It understands Brazilian and US formats (CPF, CNPJ, CEP, SSN, ZIP, phone numbers, addresses).

Documentation · Changelog · Contribuir / Contributing · Em português

$ python examples/quickstart.py
customers_br.csv  (delimiter ';', 5 rows)
column          semantic                   sensitivity     pattern
nome            Person Name / Identifier   high/restrict   
cpf             Identifier (ID)            high/mask       BR cpf
telefone        Contact / Network          high/mask       BR phone
cep             Geographic Location        medium/review   BR postal_code
endereco        Geographic Location        high/mask       BR address
cidade          Geographic Location        none/allow      
dt_cadastro     Date / Calendar            none/allow      
valor_total     Financial Value            none/allow      
ativo           Status / Indicator / Flag  none/allow

Real output for examples/customers_br.csv. The US sample, examples/customers_us.csv, is classified the same way (SSN, ZIP+4, (415) 555-2671, street_address).

When it helps

  • Personal-data scans (LGPD, GDPR, CCPA): flag CPF, SSN, phones, e-mails, and addresses, and get a mask, restrict, or review recommendation for each column.
  • Data catalogs and onboarding: label the columns of files that arrive with headers such as cd_dpto_lot, f27, or SUPPLIER_CONTACT_CODE.
  • ETL and schema mapping: decide which column is the key, the date, the amount.
  • Triage: every result says why (evidence) and whether a human should look (review_required).

Installation

pip install colsemantics

Python 3.11 or newer. Dependencies: rapidfuzz, unidecode, PyYAML.

Quick start

from colsemantics import infer_column

result = infer_column("SUPPLIER_CONTACT_CODE")
print(result["semantic"], result["confidence"], result["evidence"])

Add sampled values and opaque names become classifiable:

from colsemantics import infer_column
from colsemantics.profiling import profile_values

profile = profile_values(["SP", "RJ", "MG", "BA"])
print(infer_column("f27", profile=profile)["semantic"])  # Geographic Location

profile = profile_values(["(11) 91234-5678", "(21) 99876-5432"])
result = infer_column("f6", profile=profile)
print(result["pattern"]["message"])
# 100% of sampled values look like a Brazilian mobile phone number (e.g. (DD) 9NNNN-NNNN)

Classify a whole file (the delimiter, encoding, and column types are detected for you):

colsemantics infer employees.csv --output report.json
from colsemantics import infer_csv, infer_table

report = infer_csv("employees.csv")  # dict with one result per column
results = infer_table([{"column_name": "employee_id"}, {"column_name": "start_date"}])

What you get

Every result is a typed dictionary. This is the result for the phone column above (shortened):

{
    "semantic": "Contact / Network",
    "role": "Contact / Network", "domain": None,
    "raw_confidence": 0.98, "confidence": 0.98,
    "evidence": "100% of sampled values look like a Brazilian mobile phone number (e.g. ...)",
    "conclusive": True, "review_required": False,
    "sensitivity": {"level": "high", "action": "mask", "reason": "contact semantic"},
    "pattern": {"type": "phone", "locale": "BR", "variant": "mobile", "coverage": 1.0, ...},
    "hypotheses": [...],   # ranked alternatives
}

Field-by-field reference: docs/api.md. Recognized formats and their limits: docs/patterns.md.

Detected Recommendation
Validated CPF or SSN, street address high / mask
Person name semantic high / restrict
E-mail, phone high / mask
CNPJ, EIN, postal code, coordinates, other identifiers medium / review
Anything else none / allow

The recommendation is descriptive. colsemantics never modifies your data.

Custom vocabularies

Extend the built-in vocabulary per analysis with YAML, scoped so concurrent analyses stay isolated:

from colsemantics import infer_column, temporary_profile

with temporary_profile("pt-BR", "company-vocabulary.yaml"):
    result = infer_column("cost_bucket")

Schema and examples: docs/vocabulary.md.

Accuracy and limits

Measured on hand-written and public-catalog benchmark sets (see benchmarks/README.md):

Set Accuracy
US public datasets, names plus values (360 columns, held out) 98%
US public datasets, names only (390 columns, held out) 69%
Hand-written Brazilian and US names (89 columns) 99%
  • The calibration is provisional. confidence maps scores to precision measured on a small fixture, not on production data. Use review_required as a prompt for a human, not a guarantee.
  • Yes/no columns judged by name alone are weak (about 40%). Names such as Domestic or Safety carry no signal. With sampled values they are recognized reliably.
  • The benchmarks are small and partly synthetic. Treat them as regression checks, not as proof of accuracy on your data. Please open an issue with a column that was wrong.
  • Brazilian and US formats only. Column-name vocabulary is Portuguese and English with some Spanish.

How it compares

Tool Focus colsemantics
ydata-profiling, pandas-profiling Statistics and quality reports for a DataFrame Infers meaning (role, domain, sensitivity), not distributions
Microsoft Presidio Finds personal data inside text with recognizers and NLP Works per column, adds business roles, no model downloads
Great Expectations, Pandera Validate data against rules you write Infers what to validate in the first place
Capital One dataprofiler Model-based column labeling Lightweight (three dependencies), explainable evidence, built-in Brazilian formats

They solve neighboring problems and combine well. Check each project's documentation for its current scope.

Contributing

Contributions are welcome. See CONTRIBUTING.md for setup, checks, and the release process, and CHANGELOG.md for version history.

python -m pip install -e '.[dev]'
pytest --cov
ruff check . && ruff format --check .
mypy

If you use colsemantics in research, cite it with CITATION.cff.

Em português

colsemantics descobre o que cada coluna de uma tabela significa e quais colunas têm dados pessoais, sem precisar de esquema. Ele infere o papel (identificador, data, valor, contato, ...), o domínio de negócio e uma recomendação de privacidade a partir dos nomes, de amostras de valores e das colunas vizinhas. Reconhece formatos brasileiros e americanos: CPF, CNPJ, CEP, telefone com DDD validado, endereço, SSN, ZIP e outros.

pip install colsemantics
colsemantics infer clientes.csv --output relatorio.json
from colsemantics import infer_csv

relatorio = infer_csv("clientes.csv")  # detecta delimitador (;), encoding e tipos
for coluna in relatorio["columns"]:
    print(coluna["column_name"], coluna["semantic"], coluna["sensitivity"]["action"])
  • LGPD: sinaliza CPF, telefone, e-mail e endereço com recomendação mask, restrict ou review.
  • Explicável: cada resultado traz a evidência e se precisa de revisão humana.
  • Limites: a calibração é provisória e os benchmarks são pequenos. Colunas de sim/não só pelo nome acertam cerca de 40%; com os valores, o acerto é alto. Veja benchmarks/README.md.
  • O código e a documentação técnica estão em inglês; issues e discussões em português são bem-vindos.

License

MIT. Word lists derived from public sources are described in src/colsemantics/data/SOURCES.md.

Metadata

Release files for colsemantics 0.4.2

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

Source distribution (sdist)

Source distribution for colsemantics 0.4.2
File Size Uploaded Provenance Actions
colsemantics-0.4.2.tar.gz 103.4 kB With provenance Details for colsemantics-0.4.2.tar.gz

Built distribution (wheel)

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

Total release size: 194.5 kB

Release files / colsemantics-0.4.2.tar.gz

Download URL colsemantics-0.4.2.tar.gz
Size 103.4 kB
Tags Source
SHA-256 checksum
How to use checksums
05e2f0172140aec86d7b844ab4fcc47b4725552462daac41e2b4e9dd5390ab08
BLAKE2b-256 checksum
How to use checksums
b23a4375c11d42d44e67750484b1f0d10dba3ca15dea3406c175297782e4ca21
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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 Nov 22, 2026.

Transparency log

Release files / colsemantics-0.4.2-py3-none-any.whl

Download URL colsemantics-0.4.2-py3-none-any.whl
Size 91.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
e9b4e0ca0f2884fdd478facdac13b518b192106702429ae375d9baced9b03f94
BLAKE2b-256 checksum
How to use checksums
84881d0f606b01aaab7df69e49bbb23126b2e3760460ee4fc77e4c79012743c0
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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 Nov 22, 2026.

Transparency log

Security for colsemantics 0.4.2

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

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for colsemantics-0.4.2.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 Nov 22, 2026.

Transparency log

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