GitPedia

Python codicefiscale

:it: :credit_card: italian fiscal codes encoding, decoding and validation - codifica, decodifica e validazione del Codice Fiscale italiano.

From fabiocaccamo·Updated June 1, 2026·View on GitHub·

python-codicefiscale is a library for encode/decode Italian fiscal code - **codifica/decodifica del Codice Fiscale**. The project is written primarily in Python, distributed under the MIT License license, first published in 2017. Key topics include: anagrafe, anpr, cf, code, codice.

Latest release: 0.12.1












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

python
from codicefiscale import codicefiscale

Encode

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

Decode

python
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

python
codicefiscale.is_valid("CCCFBA85D03L219P") # True
python
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:

bash
python -m codicefiscale --help

Encode (CLI)

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

Decode (CLI)

bash
python -m codicefiscale decode CCCFBA85D03L219P

Testing

bash
# 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. 🧟‍♂️

Contributors

Showing top 12 contributors by commit count.

View all contributors on GitHub →

This article is auto-generated from fabiocaccamo/python-codicefiscale via the GitHub API.Last fetched: 6/22/2026