Skip to main content

A Python module with a collection of useful tools for Brazilians (and anyone else who wants to use it)

Project description

PyPI - License PyPI - Version PyPI - Python Version Github
Pepy Total Downloads PyPI - Downloads PyPI - Downloads PyPI - Downloads

Introduction

A Python module with a collection of useful tools for Brazilians (and anyone else who wants to use it). Take a look at CHANGELOG.md for the changes.

Brief History

I started studying Python recently and wanted to do something that would be useful. Enjoy toolkitbrazil.

Overview

Here's a quick overview of what the library has at the moment:

  • Random generation of CPF and CNPJ numbers
  • CPF and CNPJ validation
  • Checks which state a DDD belongs to
  • Checks if a year is a leap year
  • Calculates the date of Easter Sunday or Carnival Tuesday for a given year
  • Check if a specific date is Easter Sunday or Carnival Tuesday
  • Returns the capital of a state
  • Returns city and state os a zip code
  • String cleaner

How to install

pip install toolkitbrazil

Usage

import toolkitbrazil as tkb
from datetime import date

# Remove diacritics, non alpha chars, multiple spaces and convert string to upper case
print(tkb.strClean('A héalt#hy  dìet is    esse&ntiãl  for    go(od heàlth and    nutrition  '))
# Return: 'A HEALTHY DIET IS ESSENTIAL FOR GOOD HEALTH AND NUTRITION'

# Generate a random CPF
print(tkb.rngCPF())
# Sample return: 75269169703

# Generate a random CPF of specific UF
print(tkb.rngCPF('SP'))
# Sample return: 27039729890

# Validate a CPF
print(tkb.valCPF(75269169703))
# Return: True

# Generate a random CNPJ of the headquarters (branch 0001)
print(tkb.rngCNPJ())
# Sample return: 86978319000101

# Generate a random CNPJ of a branch (any branch)
print(tkb.rngCNPJfiliais())
# Sample return: 94318840326682

# Generate a random CNPJ of a desired branch (1 to 9999)
print(tkb.rngCNPJfiliais(187))
# Sample return: 50138939018728

# Validate a CNPJ
print(tkb.valCNPJ(86978319000101))
# Return: True

# Check the UF of the CPF
print(tkb.ufCPF(75269169703))
# Return: ['ES', 'RJ']

# Check the UF of the DDD or phone number (using first two digits of any number)
print(tkb.ufDDD(61))
# Return: ['DF', 'GO']
print(tkb.ufDDD(11987654321))
# Return: ['SP']

# Check the capital of a UF
print(tkb.ufCapital('SP'))
# Return ['SAO PAULO', 'SP']

# Validate a CPF and check its UF
print(tkb.valCPFuf(75269169703, 'SP'))
# Return False (it's a valid CPF but from another UF)

# Check if it is a leap year
print(tkb.valBissexto(2024))
# Return: True

# Calculates the date of Easter Sunday for a given year
print(tkb.dtPascoa(2025))
# Return 2025-04-20

# Check if a specific date is Easter Sunday
print(tkb.valPascoa(date(2025, 4, 20)))
# Return: True

# Calculates the date of Carnival Tuesday for a given year
print(tkb.dtCarnaval(2025))
# Return 2025-03-04

# Check if a specific date is Carnival Tuesday
print(tkb.valCarnaval(date(2025, 3, 4)))
# Return: True

# Generate a random car's license plate (with hyphen or not)
print(tkb.rngPlaca())
# Sample return: IDY1G29
print(tkb.rngPlaca(h=True))
# Sample return: DTQ-2D21

# Validate an e-mail
print(tkb.valEmail('test@me.com'))
# Return: True

# Check a zip code and return a list containing city and state [cidade, uf]
print(tkb.ufCep('01001-000'))
# Return ['SAO PAULO', 'SP']
print(tkb.ufCep(80020000))
# Return ['CURITIBA', 'PR']

Authors

Ricardo Colombani - @coloric

License

MIT

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

toolkitbrazil-0.0.3.tar.gz (6.6 kB view details)

Uploaded Source

Built Distribution

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

toolkitbrazil-0.0.3-py3-none-any.whl (7.2 kB view details)

Uploaded Python 3

File details

Details for the file toolkitbrazil-0.0.3.tar.gz.

File metadata

  • Download URL: toolkitbrazil-0.0.3.tar.gz
  • Upload date:
  • Size: 6.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.0

File hashes

Hashes for toolkitbrazil-0.0.3.tar.gz
Algorithm Hash digest
SHA256 401321bbbc994265e2ba04e76daa2756235d60ab264cd620f9db9690518ce0c1
MD5 9a1e6e13a0b1a07520ff02144f52ec3b
BLAKE2b-256 fd114f7ed25a19032e9e09965264af25a732035c79c5ddc526fbcb64245c0bf8

See more details on using hashes here.

File details

Details for the file toolkitbrazil-0.0.3-py3-none-any.whl.

File metadata

  • Download URL: toolkitbrazil-0.0.3-py3-none-any.whl
  • Upload date:
  • Size: 7.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.0

File hashes

Hashes for toolkitbrazil-0.0.3-py3-none-any.whl
Algorithm Hash digest
SHA256 7f1a97390306079b63d1d4b9aabe7a6e8260885c899f5077a2db0fdb5228c9ab
MD5 ab3d867f29c2390687fef51ce789afa3
BLAKE2b-256 df787e26ab8954c2f7cba712cd1e129b46773073f7ee8d2ac08d83af705a0b8f

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