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, optionallynuitandname). - Raises a descriptive
RuntimeErrorfor transport issues. - Pure Python, works anywhere
requests+beautifulsoup4can run.
Installation
pip install checknuit
Python 3.9 or newer is required.
Quick start
from checknuit import check_nuit
result = check_nuit("123456789")
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). RaisesRuntimeErrorwhen 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 extractsnuitandnamefrom 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.pyorchecknuit/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
RuntimeErrorfromsend_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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file checknuit-0.1.1.tar.gz.
File metadata
- Download URL: checknuit-0.1.1.tar.gz
- Upload date:
- Size: 7.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e073ca80e42360444327174cd8f44a462ab7bc9337d2147ee1b5aef181b04a9f
|
|
| MD5 |
0742b9c71a047c4c962d9c6397427bf1
|
|
| BLAKE2b-256 |
b574103a7fe943a5226d30cb390243d2c11dc88f6d141abedae310ce23f0b6ce
|
File details
Details for the file checknuit-0.1.1-py3-none-any.whl.
File metadata
- Download URL: checknuit-0.1.1-py3-none-any.whl
- Upload date:
- Size: 7.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
fae39370de0980a4124f389951a252404f52bcc404076c0a2858e0379e1eaebc
|
|
| MD5 |
3e716736418ee91503c688c35fa69297
|
|
| BLAKE2b-256 |
86d5ef927abf22608dfaa68314f5ba75a97cb41c695baf1280d8fc0baf428738
|