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)

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. Documents and Citizen Identity

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
is_valid_nuit("123456789")    # True
get_nuit_entity_type("400000006")  # "Collective (Quotas Companies...)"

# 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. 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.6.tar.gz (36.6 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.6-py3-none-any.whl (34.8 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: moz_utils-0.3.6.tar.gz
  • Upload date:
  • Size: 36.6 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.6.tar.gz
Algorithm Hash digest
SHA256 ee47e81e240d97664eb6a2f30bc112edd2f125e8592ce7c734e074cdafcb440f
MD5 7c89cd5301a0ec15aa742fdfe805ba66
BLAKE2b-256 2e791c3cf6112f77e4e0bc58b02829547f2b63d11e798880c67c133e2f567544

See more details on using hashes here.

File details

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

File metadata

  • Download URL: moz_utils-0.3.6-py3-none-any.whl
  • Upload date:
  • Size: 34.8 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.6-py3-none-any.whl
Algorithm Hash digest
SHA256 b518a7dff62b86631905a37b534f52d48de711172413097919a14dd2761ca4a2
MD5 d8b17dd491afb2f0164a70cca83246c6
BLAKE2b-256 edcffdd3657efc2c1cb917d5f2965454b00080da49326537b93856175ed60455

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