faker.providers.barcode.en_CA

Package Contents

Classes

EnUsBarcodeProvider

Implement barcode provider for en_US locale.

Provider

Implement barcode provider for en_CA locale.

class faker.providers.barcode.en_CA.EnUsBarcodeProvider(generator: Any)

Bases: faker.providers.barcode.Provider

Implement barcode provider for en_US locale.

Sources:

local_prefixes = ()
upc_e_base_pattern: Pattern
upc_ae_pattern1: Pattern
upc_ae_pattern2: Pattern
upc_ae_pattern3: Pattern
ean13(prefixes: faker.providers.barcode.PrefixType = (), leading_zero: Optional[bool] = None) str

Generate an EAN-13 barcode.

If leading_zero is True, the leftmost digit of the barcode will be set to 0. If False, the leftmost digit cannot be 0. If None (default), the leftmost digit can be any digit.

If a value for prefixes is specified, the result will begin with one of the sequences in prefixes and will ignore leading_zero.

This method uses the standard barcode provider’s |ean13| under the hood with the prefixes argument set to the correct value to attain the behavior described above.

Note

EAN-13 barcode that starts with a zero can be converted to UPC-A by dropping the leading zero. This may cause problems with readers that treat all of these code as UPC-A codes and drop the first digit when reading it.

You can set the argument prefixes ( or leading_zero for convenience) explicitly to avoid or to force the generated barcode to start with a zero. You can also generate actual UPC-A barcode with |EnUsBarcodeProvider.upc_a|.

Sample

Sample

leading_zero=False

Sample

leading_zero=True

Sample

prefixes=(‘00’,)

Sample

prefixes=(‘45’, ‘49’)

_convert_upc_a2e(upc_a: str) str

Convert a 12-digit UPC-A barcode to its 8-digit UPC-E equivalent.

Warning

Not all UPC-A barcodes can be converted.

_upc_ae(base: Optional[str] = None, number_system_digit: Optional[int] = None) str

Create a 12-digit UPC-A barcode that can be converted to UPC-E.

The expected value of base is a 6-digit string. If any other value is provided, this method will use a random 6-digit string instead.

The expected value of number_system_digit is the integer 0 or 1. If any other value is provided, this method will randomly choose from the two.

Please also view notes on |EnUsBarcodeProvider.upc_a| and |EnUsBarcodeProvider.upc_e| for more details.

upc_a(upc_ae_mode: bool = False, base: Optional[str] = None, number_system_digit: Optional[int] = None) str

Generate a 12-digit UPC-A barcode.

The value of upc_ae_mode controls how barcodes will be generated. If False (default), barcodes are not guaranteed to have a UPC-E equivalent. In this mode, the method uses |EnUsBarcodeProvider.ean13| under the hood, and the values of base and number_system_digit will be ignored.

If upc_ae_mode is True, the resulting barcodes are guaranteed to have a UPC-E equivalent, and the values of base and number_system_digit will be used to control what is generated.

Under this mode, base is expected to have a 6-digit string value. If any other value is supplied, a random 6-digit string will be used instead. As for number_system_digit, the expected value is a 0 or a 1. If any other value is provided, this method will randomly choose from the two.

Important

When upc_ae_mode is enabled, you might encounter instances where different values of base (e.g. '120003' and '120004') produce the same UPC-A barcode. This is normal, and the reason lies within the whole conversion process. To learn more about this and what base and number_system_digit actually represent, please refer to |EnUsBarcodeProvider.upc_e|.

Sample

Sample

upc_ae_mode=True, number_system_digit=0

Sample

upc_ae_mode=True, number_system_digit=1

Sample

upc_ae_mode=True, base=’123456’, number_system_digit=0

Sample

upc_ae_mode=True, base=’120003’, number_system_digit=0

Sample

upc_ae_mode=True, base=’120004’, number_system_digit=0

upc_e(base: Optional[str] = None, number_system_digit: Optional[int] = None, safe_mode: bool = True) str

Generate an 8-digit UPC-E barcode.

UPC-E barcodes can be expressed in 6, 7, or 8-digit formats, but this method uses the 8 digit format, since it is trivial to convert to the other two formats. The first digit (starting from the left) is controlled by number_system_digit, and it can only be a 0 or a 1. The last digit is the check digit that is inherited from the UPC-E barcode’s UPC-A equivalent. The middle six digits are collectively referred to as the base (for a lack of a better term).

On that note, this method uses base and number_system_digit to first generate a UPC-A barcode for the check digit, and what happens next depends on the value of safe_mode. The argument safe_mode exists, because there are some UPC-E values that share the same UPC-A equivalent. For example, any UPC-E barcode of the form abc0000d, abc0003d, and abc0004d share the same UPC-A value abc00000000d, but that UPC-A value will only convert to abc0000d because of (a) how UPC-E is just a zero-suppressed version of UPC-A and (b) the rules around the conversion.

If safe_mode is True (default), this method performs another set of conversions to guarantee that the UPC-E barcodes generated can be converted to UPC-A, and that UPC-A barcode can be converted back to the original UPC-E barcode. Using the example above, even if the bases 120003 or 120004 are used, the resulting UPC-E barcode will always use the base 120000.

If safe_mode is False, then the number_system_digit, base, and the computed check digit will just be concatenated together to produce the UPC-E barcode, and attempting to convert the barcode to UPC-A and back again to UPC-E will exhibit the behavior described above.

Sample

Sample

base=’123456’

Sample

base=’123456’, number_system_digit=0

Sample

base=’123456’, number_system_digit=1

Sample

base=’120000’, number_system_digit=0

Sample

base=’120003’, number_system_digit=0

Sample

base=’120004’, number_system_digit=0

Sample

base=’120000’, number_system_digit=0, safe_mode=False

Sample

base=’120003’, number_system_digit=0, safe_mode=False

Sample

base=’120004’, number_system_digit=0, safe_mode=False

class faker.providers.barcode.en_CA.Provider(generator: Any)

Bases: faker.providers.barcode.en_US.Provider

Implement barcode provider for en_CA locale.

Canada uses UPC as well, so there are similarities between this and the en_US implementation.

Sources:

local_prefixes = ()