Name | ccpf JSON |
Version |
1.0.0
JSON |
| download |
home_page | None |
Summary | CPF validation, generation and masking |
upload_time | 2024-10-30 02:22:20 |
maintainer | None |
docs_url | None |
author | None |
requires_python | >=3.10 |
license | MIT |
keywords |
cpf
validation
generation
mask
|
VCS |
|
bugtrack_url |
|
requirements |
No requirements were recorded.
|
Travis-CI |
No Travis.
|
coveralls test coverage |
No coveralls.
|
## ccpf
A CPF (brazilian register numbers for persons) library that can:
* Validate CPFs
* Generate random CPFs
* Apply and remove masks from CPFs
* Check if CPFs are masked
### Install
Just do `pip3 install ccpf` and you are good to go.
### How to use
After `import`ing `ccpf` you can:
* `generate()` - Generate a random valid unmasked CPF.
```
import ccpf
cpf = ccpf.generate()
assert ccpf.validate(cpf)
```
* `validate(cpf)` - Validate if a string is a valid CPF. Works for masked and unmasked CPFs.
```
import ccpf
cpf = ccpf.generate()
assert ccpf.validate(cpf)
```
* `has_mask(cpf)` - Return wheter or not the given CPF is masked. If CPF format is invalid, it will raise a `CPFInvalidFormat` exception.
```
import ccpf
cpf = ccpf.generate()
assert not ccpf.has_mask(cpf)
```
* `mask(cpf)` - Return the masked version of the given CPF. If the CPF is already masked, just return it. If CPF format is invalid, it will raise a `CPFInvalidFormat` exception.
```
import ccpf
cpf = ccpf.generate()
assert not ccpf.has_mask(cpf)
masked = ccpf.mask(cpf)
assert ccpf.has_mask(masked)
masked2 = ccpf.mask(masked)
assert ccpf.has_mask(masked2)
```
* `unmask(cpf)` - Return unmasked version of the given CPF. If the CPF is already unmasked, just return it. If CPF format is invalid, it will raise a `CPFInvalidFormat` exception.
```
import ccpf
cpf = ccpf.generate()
assert not ccpf.has_mask(cpf)
unmasked = ccpf.unmask(cpf)
assert not ccpf.has_mask(unmasked)
masked = ccpf.mask(unmasked)
assert ccpf.has_mask(masked)
unmasked2 = ccpf.unmask(masked)
assert not ccpf.has_mask(unmasked2)
```
#### `CPFInvalidFormat`
A CPF may have a valid _format_, but be invalid:
* without mask but invalid:
```
invalid_cpf_with_right_format = '12345678901'
assert not ccpf.validate(invalid_cpf_with_right_format)
error = False
try:
ccpf.unmask(invalid_cpf_with_right_format)
except ccpf.CPFInvalidFormat:
error = True
finally:
assert not error
```
* with mask but invalid.
```
invalid_cpf_with_right_format = '123.456.789-01'
assert not ccpf.validate(invalid_cpf_with_right_format)
error = False
try:
ccpf.unmask(invalid_cpf_with_right_format)
except ccpf.CPFInvalidFormat:
error = True
finally:
assert not error
```
* `CPFInvalidFormat` will be raised when the format is invalid. It does not say whether the CPF itself is invalid or not.
```
cpf_with_wrong_format = 'thisisclearlynotinthecpfformat'
assert not ccpf.validate(cpf_with_wrong_format)
error = False
try:
ccpf.unmask(cpf_with_wrong_format)
except ccpf.CPFInvalidFormat:
error = True
finally:
assert error
```
### Run tests
Just execute `tox` by calling it:
```
tox
```
Raw data
{
"_id": null,
"home_page": null,
"name": "ccpf",
"maintainer": null,
"docs_url": null,
"requires_python": ">=3.10",
"maintainer_email": null,
"keywords": "cpf, validation, generation, mask",
"author": null,
"author_email": "felipeasimos <felipe.asimos@gmail.com>",
"download_url": "https://files.pythonhosted.org/packages/85/23/d9c5aaf3560bc067e90c7f2bd4a08edb3150f8722acf937256968cd56c3f/ccpf-1.0.0.tar.gz",
"platform": null,
"description": "## ccpf\n\nA CPF (brazilian register numbers for persons) library that can:\n* Validate CPFs\n* Generate random CPFs\n* Apply and remove masks from CPFs\n* Check if CPFs are masked\n\n### Install\n\nJust do `pip3 install ccpf` and you are good to go.\n\n### How to use\n\nAfter `import`ing `ccpf` you can:\n\n* `generate()` - Generate a random valid unmasked CPF.\n\n```\nimport ccpf\ncpf = ccpf.generate()\nassert ccpf.validate(cpf)\n```\n\n* `validate(cpf)` - Validate if a string is a valid CPF. Works for masked and unmasked CPFs.\n\n```\nimport ccpf\ncpf = ccpf.generate()\nassert ccpf.validate(cpf)\n```\n\n* `has_mask(cpf)` - Return wheter or not the given CPF is masked. If CPF format is invalid, it will raise a `CPFInvalidFormat` exception.\n\n```\nimport ccpf\ncpf = ccpf.generate()\nassert not ccpf.has_mask(cpf)\n```\n\n* `mask(cpf)` - Return the masked version of the given CPF. If the CPF is already masked, just return it. If CPF format is invalid, it will raise a `CPFInvalidFormat` exception.\n\n```\nimport ccpf\ncpf = ccpf.generate()\nassert not ccpf.has_mask(cpf)\nmasked = ccpf.mask(cpf)\nassert ccpf.has_mask(masked)\nmasked2 = ccpf.mask(masked)\nassert ccpf.has_mask(masked2)\n```\n\n* `unmask(cpf)` - Return unmasked version of the given CPF. If the CPF is already unmasked, just return it. If CPF format is invalid, it will raise a `CPFInvalidFormat` exception.\n\n```\nimport ccpf\ncpf = ccpf.generate()\nassert not ccpf.has_mask(cpf)\nunmasked = ccpf.unmask(cpf)\nassert not ccpf.has_mask(unmasked)\nmasked = ccpf.mask(unmasked)\nassert ccpf.has_mask(masked)\nunmasked2 = ccpf.unmask(masked)\nassert not ccpf.has_mask(unmasked2)\n```\n\n#### `CPFInvalidFormat`\n\nA CPF may have a valid _format_, but be invalid:\n\n* without mask but invalid: \n```\ninvalid_cpf_with_right_format = '12345678901'\nassert not ccpf.validate(invalid_cpf_with_right_format)\nerror = False\ntry:\n ccpf.unmask(invalid_cpf_with_right_format)\nexcept ccpf.CPFInvalidFormat:\n error = True\nfinally:\n assert not error\n```\n* with mask but invalid.\n```\ninvalid_cpf_with_right_format = '123.456.789-01'\nassert not ccpf.validate(invalid_cpf_with_right_format)\nerror = False\ntry:\n ccpf.unmask(invalid_cpf_with_right_format)\nexcept ccpf.CPFInvalidFormat:\n error = True\nfinally:\n assert not error\n```\n\n* `CPFInvalidFormat` will be raised when the format is invalid. It does not say whether the CPF itself is invalid or not.\n\n```\ncpf_with_wrong_format = 'thisisclearlynotinthecpfformat'\nassert not ccpf.validate(cpf_with_wrong_format)\nerror = False\ntry:\n ccpf.unmask(cpf_with_wrong_format)\nexcept ccpf.CPFInvalidFormat:\n error = True\nfinally:\n assert error\n```\n\n### Run tests\n\nJust execute `tox` by calling it: \n\n```\ntox\n```\n",
"bugtrack_url": null,
"license": "MIT",
"summary": "CPF validation, generation and masking",
"version": "1.0.0",
"project_urls": null,
"split_keywords": [
"cpf",
" validation",
" generation",
" mask"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "8523d9c5aaf3560bc067e90c7f2bd4a08edb3150f8722acf937256968cd56c3f",
"md5": "02b259d46ee2984db48473e26aa5e7dc",
"sha256": "d804180633116c18f09d70fc4c460daee79bac288943a65bb56cec7ef12c976f"
},
"downloads": -1,
"filename": "ccpf-1.0.0.tar.gz",
"has_sig": false,
"md5_digest": "02b259d46ee2984db48473e26aa5e7dc",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.10",
"size": 60651,
"upload_time": "2024-10-30T02:22:20",
"upload_time_iso_8601": "2024-10-30T02:22:20.575882Z",
"url": "https://files.pythonhosted.org/packages/85/23/d9c5aaf3560bc067e90c7f2bd4a08edb3150f8722acf937256968cd56c3f/ccpf-1.0.0.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-10-30 02:22:20",
"github": false,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"lcname": "ccpf"
}