Skip to main content

Funções de utilidade para Moçambique. Validação de NUIT, documentos e formatação de telefones.

Project description

moz-utils

Python (Django/FastAPI)

PyPI Version PyPI Downloads

The digital foundation of Mozambican identity. The definitive Swiss army knife for validations, postal codes, and financial ecosystems in Mozambique, natively ported to the Python ecosystem.


📜 The Vision

In Mozambique, digital accuracy is the foundation of the future. From the pulse of mobile wallets in the squares to the rigorous structure of the National ID (BI), moz-utils exists to ensure that every piece of data that crosses your backend (Django, Flask, FastAPI) or Data Science script is validated, structured, and authentic.

Built impeccably for the Python ecosystem, this package is more than a library — it is the open-source validation infrastructure our country deserves. Clean code, tested, and poetically engineered for Mozambique.


📦 Installation

Install using pip:

pip install moz-utils

Or using poetry:

poetry add moz-utils

🚀 API Reference Guide

1. Identity & Documents

from moz_utils import (
    is_valid_bi,
    is_valid_nuit,
    get_nuit_entity_type,
    is_valid_dire,
    is_valid_passport,
    is_valid_driving_license
)

# National ID (12 digits + 1 letter)
is_valid_bi("110101234567A")  # True

# NUIT - Unique Tax Identification Number (Per AT Decree n. 28/2012)
is_valid_nuit("401626638")    # True
get_nuit_entity_type("400000006")  # "Pessoas Colectivas"
get_nuit_entity_type("100000008")  # "Pessoas Singulares"

# DIRE - Foreign Resident Identification Document
is_valid_dire("00008312C")    # True

# Passport and Driving License
is_valid_passport("AO1234567")       # True
is_valid_driving_license("M123456")   # True

2. Name & String Sanitization

Clean up dirty user input from forms before saving to your database:

from moz_utils import (
    is_valid_name,
    sanitize_name,
    sanitize_document_field,
    sanitize_alphanumeric_field
)

is_valid_name("Edmilson O'Brian-Muacigarro") # True
is_valid_name("Edmilson 123")                # False

sanitize_name("  EDMILSON  muacigarro ")    # "Edmilson Muacigarro"
sanitize_name("João", all_caps=True)        # "JOÃO"

sanitize_document_field("123 456-789")       # "123456789"
sanitize_alphanumeric_field("110 101 a")     # "110101A"

3. Financial Toolkit (Metical)

from moz_utils import format_mzn, parse_mzn

# Format database floats into official AT formats
format_mzn(1500)          # "1 500,00 MT"
format_mzn(50000, "MZN")  # "50 000,00 MZN"

# Parse dirty strings back into database floats
parse_mzn("1.500,00 MT")  # 1500.00
parse_mzn("1 500,00MZN")  # 1500.00

4. Financial Ecosystem and Telecommunications

Deep mapping of the Mozambican digital circulatory system — identifies operators and the pulse of associated mobile wallets.

from moz_utils import (
    is_valid_mozambican_phone,
    format_mozambican_phone,
    get_mobile_operator,
    get_mobile_wallet,
    build_whatsapp_url
)

# Validation and Formatting
is_valid_mozambican_phone("841234567")  # True
format_mozambican_phone("841234567")   # "+258 84 123 4567"

# Telecom and Financial Intelligence
get_mobile_operator("841234567")  # "Vodacom"
get_mobile_wallet("841234567")    # "M-Pesa"
get_mobile_wallet("821234567")    # "mKesh"
get_mobile_wallet("861234567")    # "e-Mola"

# Social Connections
build_whatsapp_url("841234567", "Hello, Mozambique!") 
# "https://wa.me/258841234567?text=Hello%2C%20Mozambique%21"

3. Postal Codes (Legacy and New CEP)

A graceful transition between the past and the future: from the old post office stations to the geo-referenced New CEP.

from moz_utils import (
    is_valid_new_cep,
    suggest_ceps,
    is_valid_postal_code,
    get_postal_code_locality
)

# The Future (New CEP: Province, District, and Locality)
is_valid_new_cep("0101-01")  # True

# Intelligent Suggestion Engine (Supports Legacy -> New Transition)
# Search by the old code "3100" (Nampula) or by a neighborhood
suggest_ceps("3100")
suggest_ceps("Namutequeliua")

# The Legacy
is_valid_postal_code("3100")            # True
get_postal_code_locality("3100")        # "Nampula"

4. National Geography and Finances

from moz_utils import (
    format_mzn,
    get_mozambique_provinces,
    get_districts_by_province
)

# Monumental Value
format_mzn(1250.5)         # "1 250,50 MT"

# Full Geography
provinces = get_mozambique_provinces()
nampula_districts = get_districts_by_province("npl")

🤝 Rules of Conduct and Contribution

This is not just any project. It is a project of national pride. We ask for excellence in code, compassion with colleagues, and the ambition to make the Mozambican web world-class. Read our CODE_OF_CONDUCT.md in the project root.

📄 License

The code lives and breathes the freedom of Open Source. Licensed under AGPL-3.0-or-later.


Developed by Open Source Contributors & supported by Edmilson Muacigarro


🧮 O Algoritmo NUIT (A Verdadeira Fórmula Moçambicana)

Ao contrário do NIF de Portugal (que usa multiplicadores de 9 a 2), a Autoridade Tributária de Moçambique utiliza a seguinte matriz de pesos para calcular o Módulo 11 do NUIT.

A Fórmula e os Pesos Oficiais:

NUIT a Validar: 401626638

Posição:   1   2   3   4   5   6   7   8
Dígitos:   4   0   1   6   2   6   6   3
Pesos:     8   9   4   5   6   7   8   9
           |   |   |   |   |   |   |   |
Mult:     32 + 0 + 4 +30 +12 +42 +48 +27 = 195 (Soma)

Cálculo do Módulo 11:
1. Resto = Soma % 11
   195 % 11 = 8
2. O "Resto" é o Índice (Posição 0 a 10) na string de controlo "01234567891".
3. A 8ª posição de "01234567891" é '8'.
4. Como o 9º dígito do NUIT (Dígito de Controlo) é '8', o NUIT é Válido!

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

moz_utils-0.3.9.tar.gz (39.1 kB view details)

Uploaded Source

Built Distribution

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

moz_utils-0.3.9-py3-none-any.whl (35.2 kB view details)

Uploaded Python 3

File details

Details for the file moz_utils-0.3.9.tar.gz.

File metadata

  • Download URL: moz_utils-0.3.9.tar.gz
  • Upload date:
  • Size: 39.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for moz_utils-0.3.9.tar.gz
Algorithm Hash digest
SHA256 745e487d3c64bcd993e0a989521ffe5f8e0a0461f86c13ebaa02680caaee33db
MD5 c4133661aa27cccd01ecd49b6b04a09a
BLAKE2b-256 af4e0f9916cf9efddb7d1121324c0fbccd227ce77e4d9623d570f354d2784dea

See more details on using hashes here.

File details

Details for the file moz_utils-0.3.9-py3-none-any.whl.

File metadata

  • Download URL: moz_utils-0.3.9-py3-none-any.whl
  • Upload date:
  • Size: 35.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for moz_utils-0.3.9-py3-none-any.whl
Algorithm Hash digest
SHA256 83da9a9e2cc3eba7c9a3189cdc334551efe05622d96e2d84672b0efd2e496915
MD5 758e6bb5f8565ae3001e3417821d1465
BLAKE2b-256 9d048f42c4a034821b70602293a4a8830536874ca5188ddd1509a50393fee940

See more details on using hashes here.

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