Skip to main content

FebrabanCode Class

The FebrabanCode class is designed to parse and validate Febraban codes commonly used in Brazil, such as bar codes and lines. This class provides methods to extract information from Febraban codes, validate their integrity, and retrieve specific details.

Usage

To use this class, follow these steps:

  1. Instantiate the Class: Create an instance of the FebrabanCode class by passing the Febraban code (either bar or line) as a string parameter.

  2. Retrieve Information: Utilize the provided methods to retrieve information from the Febraban code, such as bank details, currency, value, and expiration date.

  3. Validation: Use the validate() method to check the integrity of the provided Febraban code. This method validates the control digits and ensures the code's correctness.

Class Methods

__init__(bar_code: str)

Constructor method to initialize the FebrabanCode object. It takes a Febraban code (either bar or line) as input.

get_code_info() -> Dict[str, Union[str, date, float]]

Returns a dictionary containing information extracted from the Febraban code, including bank details, currency, expiration date, and value.

get_bar() -> str

Returns the Febraban bar code as a string.

get_line(formatted: bool = False) -> str

Returns the Febraban line code as a string. If formatted is set to True, the line code is returned with formatting for readability.

validate() -> bool

Validates the integrity of the Febraban code. Returns True if the code is valid, otherwise False.

Internal Methods

__code_match(code: str) -> str

Internal method to match and sanitize the input Febraban code.

__get_dv_module_10(number: str) -> int

Calculates the verification digit using the module 10 algorithm.

__get_dv_module_11(number: str) -> int

Calculates the verification digit using the module 11 algorithm.

__get_expiry(expiry_factor: str) -> date

Calculates the expiration date based on the provided expiration factor.

__convert_value_factor(value: str) -> float

Converts the value factor from the Febraban code to a float value.

__get_info_from_line(line: str) -> Dict[str, Union[str, date, float]]

Extracts information from the line code of the Febraban code.

__get_info_from_bar(bar: str) -> Dict[str, Union[str, date, float]]

Extracts information from the bar code of the Febraban code.

__get_info_from_code(code: str) -> Dict[str, Union[str, date, float]]

Determines the type of Febraban code (bar or line) and extracts information accordingly.

Error Handling

  • Raises AttributeError if the provided input is not a string.
  • Raises ValueError if the length of the code is not valid (either 47 digits for the line or 44 digits for the bar).

Dependencies

  • datetime: Standard Python library for date and time operations.
  • timedelta: Standard Python library for representing differences between dates or times.
  • re: Standard Python library for regular expressions.
  • typing: Standard Python library for type hints.

Example

from febraban_code import FebrabanCode

# Instantiate with a Febraban code
febraban_code = FebrabanCode("34191091001219011004141140141141000000120100")

# Retrieve information
info = febraban_code.get_code_info()
print(info)

# Validate the code
is_valid = febraban_code.validate()
print(is_valid)

Metadata

Release files for febraban-code 0.1.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for febraban-code 0.1.1
File Size Uploaded Provenance Actions
febraban_code-0.1.1.tar.gz 4.4 kB Without provenance Details for febraban_code-0.1.1.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for febraban-code 0.1.1
File Interpreter ABI Platform Actions
febraban_code-0.1.1-py2.py3-none-any.whl Python 2, Python 3 none any Details for febraban_code-0.1.1-py2.py3-none-any.whl

Total release size: 9.6 kB

Release files / febraban_code-0.1.1.tar.gz

Download URL febraban_code-0.1.1.tar.gz
Size 4.4 kB
Tags Source
SHA-256 checksum
How to use checksums
f6e882cce2f3977741051dad07df68f7793fc6ee99247beb7ed223959747c1c5
BLAKE2b-256 checksum
How to use checksums
bbd428db3b120b0e5ca1570060c82302ca6d3f83ee55dd6b45f4dc7a9a5f4c5f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.8.1 CPython/3.11.2 Linux/6.1.0-18-amd64

Release files / febraban_code-0.1.1-py2.py3-none-any.whl

Download URL febraban_code-0.1.1-py2.py3-none-any.whl
Size 5.2 kB
Tags Python 2 Python 3
SHA-256 checksum
How to use checksums
294751db0f83cd73188719a267868084b4de812df3aa56297111958c37665e0d
BLAKE2b-256 checksum
How to use checksums
adfbf398a32eb64957637b818c23ad4c57c0dccff90262b0891f3f41e7370463
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.8.1 CPython/3.11.2 Linux/6.1.0-18-amd64

Security for febraban-code 0.1.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.1.1 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page