Skip to main content

Lib for checking nuit validity, and return nuit data

Project description

checknuit

Python helper for validating a Mozambican NUIT (Número Único de Identificação Tributária) by mirroring the public POST request that the tax portal (nuit.at.gov.mz) performs. The HTML response is parsed with BeautifulSoup and summarized into a tiny Python dictionary that is easy to consume from scripts, CLIs, and backend jobs.

⚠️ Heads-up: calls are forwarded to the official website. Be gentle, adopt backoffs, and only resolve NUITs that you are authorized to query.

Features

  • Keeps an up-to-date copy of the Firefox POST payload the portal expects.
  • Returns a deterministic dictionary (is_valid, optionally nuit and name).
  • Raises a descriptive RuntimeError for transport issues.
  • Pure Python, works anywhere requests + beautifulsoup4 can run.

Installation

pip install checknuit

Need to hack on the package itself? Install it from source:

git clone <repo-url>
cd checknuit
python -m venv .venv && source .venv/bin/activate
pip install -U pip
pip install -e .

Python 3.9 or newer is required.

Quick start

from checknuit import check_nuit

result = check_nuit("141277286")

if result["is_valid"]:
    print(f"NUIT {result['nuit']} belongs to {result['name']}")
else:
    print("Invalid NUIT or lookup failed")

Response format

check_nuit() always returns a dictionary with at least the is_valid key:

{"is_valid": True, "nuit": "141277286", "name": "DOE, MARIA"}

If the remote site flags the number as invalid—or parsing fails—you get:

{"is_valid": False}

The helper never raises for semantic errors: validation state always lives in the returned dictionary. Only networking issues or unexpected HTTP errors raise.

API reference

  • checknuit.check_nuit(nuit: str) -> dict – High-level helper that orchestrates the POST request and HTML parsing; safe to call in applications.
  • checknuit.web.send_post(nuit: str) -> str – Mirrors the Firefox network call (headers, cookies, payload). Raises RuntimeError when the POST fails.
  • checknuit.utils.is_nuit_valid(html: str) -> dict – Returns the final payload ({"is_valid": False} or {"is_valid": True, ...}) based on the HTML string.
  • checknuit.utils.extract_data(html: str) -> dict – Internal helper that extracts nuit and name from the <a id="GridView1_lnkNome_0"> node.

Reusing the lower-level helpers lets you plug your own HTTP client or cached responses when needed.

Troubleshooting & limitations

  • Portal changes: If the upstream page changes IDs, hidden fields, or validation semantics, update checknuit/web.py or checknuit/utils.py.
  • Blocking / rate limits: The public form may throttle or block scripted traffic. Introduce retries with exponential backoff in your application.
  • Network environments: Corporate proxies or offline environments will cause RuntimeError from send_post; wrap calls in your own error handling.

Development

python -m venv .venv && source .venv/bin/activate
pip install -r requirements.txt
python test.py  # smoke test against the live portal
pytest          # when unit tests are added

Feel free to adapt the payload or headers in checknuit/web.py if the upstream site rotates any form fields or anti-bot measures.

License

MIT — see LICENSE once it is added. Until then, treat the project as all-rights-reserved by the original author.

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

checknuit-0.1.0.tar.gz (7.5 kB view details)

Uploaded Source

Built Distribution

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

checknuit-0.1.0-py3-none-any.whl (8.0 kB view details)

Uploaded Python 3

File details

Details for the file checknuit-0.1.0.tar.gz.

File metadata

  • Download URL: checknuit-0.1.0.tar.gz
  • Upload date:
  • Size: 7.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.9

File hashes

Hashes for checknuit-0.1.0.tar.gz
Algorithm Hash digest
SHA256 3342dc3c3e3754d7f3a0eee67d1ea4b233b1c8cfc9f05872adc8aa0f459440bb
MD5 780d8339d2ae340449f1f61855d12a22
BLAKE2b-256 1bf642df58d58df9015696c8bf0faf09c247f69cea764e5296f861c3ca2eb848

See more details on using hashes here.

File details

Details for the file checknuit-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: checknuit-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 8.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.9

File hashes

Hashes for checknuit-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 e721f8f68b1c0cbadc1c1fdfa01e5cfd62f3fd2790b03f54e7a44ed28b6b2f47
MD5 e4309322a3e111f6c94a222d6403696c
BLAKE2b-256 88fc117a25727fa86077807d7f9a50522f9878a9bb0e7f3eb14a223143c9d2ed

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