Skip to main content

encode / decode italian fiscal codes - codifica / decodifica del Codice Fiscale italiano.

Project description

python-codicefiscale

python-codicefiscale is a library for encode/decode Italian fiscal code - codifica/decodifica del Codice Fiscale.

Codice Fiscale

Features

  • NEW Auto-updated data (once a week) directly from ANPR data-source.
  • NEW Command Line Interface available.
  • Transliteration for name/surname
  • Multiple birthdate formats (date/string) (you can see all the supported string formats here)
  • Automatic birthplace city/foreign-country code detection from name
  • Omocodia support

Installation

pip install python-codicefiscale

Usage

Python

Import

from codicefiscale import codicefiscale

Encode

codicefiscale.encode(
    lastname="Caccamo",
    firstname="Fabio",
    gender="M",
    birthdate="03/04/1985",
    birthplace="Torino",
)

# "CCCFBA85D03L219P"

Decode

codicefiscale.decode("CCCFBA85D03L219P")

# {
#     "code": "CCCFBA85D03L219P",
#     "gender": "M",
#     "birthdate": datetime.datetime(1985, 4, 3, 0, 0),
#     "birthplace": {
#         "name": "TORINO"
#         "province": "TO",
#         "code": "L219",
#     },
#     "firstname_options": [
#         "Fabio",
#     ],
#     "omocodes": [
#         "CCCFBA85D03L219P",
#         "CCCFBA85D03L21VE",
#         "CCCFBA85D03L2MVP",
#         "CCCFBA85D03LNMVE",
#         "CCCFBA85D0PLNMVA",
#         "CCCFBA85DLPLNMVL",
#         "CCCFBA8RDLPLNMVX",
#         "CCCFBAURDLPLNMVU",
#     ],
#     "raw": {
#         "code": "CCCFBA85D03L219P",
#         "lastname": "CCC",
#         "firstname": "FBA",
#         "birthdate": "85D03",
#         "birthdate_year": "85"
#         "birthdate_month": "D",
#         "birthdate_day": "03",
#         "birthplace": "L219",
#         "cin": "P",
#     },
# }

[!TIP] Name suggestions: The firstname_options field contains a list of possible first names matching the encoded firstname code. For Italian birthplaces, in approximately 60% of cases, it returns a single name, providing near-certain identification. In other cases, it returns a list of possible names. For foreign birthplaces, the list is empty.

Check

codicefiscale.is_valid("CCCFBA85D03L219P")

# True
codicefiscale.is_omocode("CCCFBA85D03L219P")

# False

Command Line

[!CAUTION] If sensitive data is written to a log entry it could be exposed to an attacker who gains access to the logs.

This library can be used also as a CLI tool, for more info run:

python -m codicefiscale --help

Encode (CLI)

python -m codicefiscale encode --firstname Fabio --lastname Caccamo --gender M --birthdate 03/04/1985 --birthplace Torino

Decode (CLI)

python -m codicefiscale decode CCCFBA85D03L219P

Testing

# clone repository
git clone https://github.com/fabiocaccamo/python-codicefiscale.git && cd python-codicefiscale

# create virtualenv and activate it
python -m venv venv && . venv/bin/activate

# upgrade pip
python -m pip install --upgrade pip

# install requirements
pip install -r requirements.txt -r requirements-test.txt

# install pre-commit to run formatters and linters
pre-commit install --install-hooks

# run tests using tox
tox

# or run tests using pytest
pytest

License

Released under MIT License.


Supporting

  • :star: Star this project on GitHub
  • :octocat: Follow me on GitHub
  • :blue_heart: Follow me on Bluesky
  • :moneybag: Sponsor me on Github

See also

  • python-benedict - dict subclass with keylist/keypath support, I/O shortcuts (base64, csv, json, pickle, plist, query-string, toml, xml, yaml) and many utilities. 📘

  • python-fontbro - friendly font operations. 🧢

  • python-fsutil - file-system utilities for lazy devs. 🧟‍♂️

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

python_codicefiscale-0.12.0.tar.gz (428.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

python_codicefiscale-0.12.0-py3-none-any.whl (437.8 kB view details)

Uploaded Python 3

File details

Details for the file python_codicefiscale-0.12.0.tar.gz.

File metadata

  • Download URL: python_codicefiscale-0.12.0.tar.gz
  • Upload date:
  • Size: 428.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.13

File hashes

Hashes for python_codicefiscale-0.12.0.tar.gz
Algorithm Hash digest
SHA256 ae6adffbe5855856ea1a0f085d63a051d49b4a1c6c6da6b600cc2c0be8e3ee5a
MD5 2cb5b6cfda732bc73825ee5e4a377d06
BLAKE2b-256 1fcc7f8c34e1b31a56453bb3695c5765894c5bb14c61431c9c03070bf4db449b

See more details on using hashes here.

Provenance

The following attestation bundles were made for python_codicefiscale-0.12.0.tar.gz:

Publisher: create-release.yml on fabiocaccamo/python-codicefiscale

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file python_codicefiscale-0.12.0-py3-none-any.whl.

File metadata

File hashes

Hashes for python_codicefiscale-0.12.0-py3-none-any.whl
Algorithm Hash digest
SHA256 bd82ef78325ee3c84588f20a9d8e2b5baa847e5e0bea513e3cb9f2babb641582
MD5 bde65e2cc8201bf56176ef23164c97d0
BLAKE2b-256 428eccc8e2802e980f722eadd1d456ea06d8616877bd845bff16ed2e9d51cffe

See more details on using hashes here.

Provenance

The following attestation bundles were made for python_codicefiscale-0.12.0-py3-none-any.whl:

Publisher: create-release.yml on fabiocaccamo/python-codicefiscale

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page