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

# 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

# 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.2.tar.gz (6.2 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.2-py3-none-any.whl (6.8 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: toolkitbrazil-0.0.2.tar.gz
  • Upload date:
  • Size: 6.2 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.2.tar.gz
Algorithm Hash digest
SHA256 ddfd9ca813d9e52cd2f7227d7dda79245f9d9031d75412ce8cba2f997d348f2a
MD5 45b7df2ad0c7d0b4ce87b83eb69534ae
BLAKE2b-256 faf23481b719c6391f90d3200bf91dd53175b4734d51c08abbc3910411e350c8

See more details on using hashes here.

File details

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

File metadata

  • Download URL: toolkitbrazil-0.0.2-py3-none-any.whl
  • Upload date:
  • Size: 6.8 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.2-py3-none-any.whl
Algorithm Hash digest
SHA256 a090f67d3140151f8a744e5669f0eea094b0c16f4e95a05f3d765ea1aa3ccf7f
MD5 e6a63010078fe791c5c96b3c9b48a1e5
BLAKE2b-256 cb028699f89fdc7ae0c5040ad8428d1f839e506fcb6c992fab84142a1338f3b6

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