Skip to main content

barkod

GTIN parsing, canonicalisation, match keys and GS1 classification. Written in Rust; this is the Python binding.

pip install barkod
import barkod

barkod.store_form("7350053850019")   # '07350053850019'  — padded, check digit kept
barkod.store_form("lek")             # 'lek'             — untouched, never blanked
barkod.key("7350053850019")          # GtinKey('07350053850010')
barkod.key("073905259077450")        # None              — 15 digits is not a GTIN

p = barkod.parse("370245100000000123")
p.is_gtin                            # False
p.reason                             # 'too_long'
p.message                            # 'More than 14 digits — not a GTIN'
p.raw                                # '370245100000000123' — always kept

The domain

Every function agrees that a GTIN is 8 to 14 digits and differs only on what it does inside that range. Outside it, store_form hands the input back untouched and key returns None. A lossy transformation is not a licence to be more permissive about what counts as a GTIN.

The key is not a GTIN

key() returns a GtinKey, not a str. It has no __str__, so printing one gives GtinKey('07390525907740') rather than a bare number — a key that leaks into an export is visibly wrong instead of a plausible fabricated identifier. Roughly nine in ten keys end in a check digit no product has.

key = barkod.key("7390525907745")
f"{key}"            # "GtinKey('07390525907740')"
key.as_key_str()    # '07390525907740'  — say it out loud

Columns

store_form_many, key_strings and parse_many take a whole column and release the GIL for the work. They accept whatever the column actually holds — str, int, float or None.

import polars as pl

df = df.with_columns(
    pl.Series("gtin_key", barkod.key_strings(df["gtin"].to_list()))
)

key_strings is named for what it does. It is the one place the type distinction is deliberately dropped, because a dataframe column needs strings, so the call site has to say so.

Classify, never reject

An invalid check digit does not mean "not a GTIN". Variable-weight in-store codes and internal PLUs are live products that fail GS1 Mod-10 by design.

g = barkod.parse("02011030000000").gtin
g.check_digit_is_valid        # False
g.allocation                  # 'restricted_circulation_region'
g.measure_field_looks_zeroed  # True  — a named guess, not a verdict

Full documentation: https://github.com/mommo-codes/barkod

MIT licensed.

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distributions

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

barkod-0.1.2-cp38-abi3-win_amd64.whl (163.1 kB view details)

Uploaded CPython 3.8+Windows x86-64

barkod-0.1.2-cp38-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (306.3 kB view details)

Uploaded CPython 3.8+manylinux: glibc 2.17+ x86-64

barkod-0.1.2-cp38-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (302.3 kB view details)

Uploaded CPython 3.8+manylinux: glibc 2.17+ ARM64

barkod-0.1.2-cp38-abi3-macosx_11_0_arm64.whl (267.9 kB view details)

Uploaded CPython 3.8+macOS 11.0+ ARM64

File details

Details for the file barkod-0.1.2-cp38-abi3-win_amd64.whl.

File metadata

  • Download URL: barkod-0.1.2-cp38-abi3-win_amd64.whl
  • Upload date:
  • Size: 163.1 kB
  • Tags: CPython 3.8+, Windows x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for barkod-0.1.2-cp38-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 e9ba8e443e146b5a31f3cd4a3a06db52db521c4f5055beedc0ee835c52bf0302
MD5 97b988504b25f07af405883af446df10
BLAKE2b-256 830f011f98dc1cbe1c01b48eb56ccffae4157baae5a64183cde24da1a15bafe3

See more details on using hashes here.

Provenance

The following attestation bundles were made for barkod-0.1.2-cp38-abi3-win_amd64.whl:

Publisher: release.yml on mommo-codes/barkod

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file barkod-0.1.2-cp38-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for barkod-0.1.2-cp38-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 0f64612e952f6869c613606d47a9ecbfb42a74f0f6ce189b9cfd71e33b59f0e0
MD5 0aba4cec0f1de7c221a81f15e062e4b5
BLAKE2b-256 0d991a49b9f30fac9141797d2fec60cccece57671c7cad6bb4beb096aaea7971

See more details on using hashes here.

Provenance

The following attestation bundles were made for barkod-0.1.2-cp38-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl:

Publisher: release.yml on mommo-codes/barkod

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file barkod-0.1.2-cp38-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for barkod-0.1.2-cp38-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 abbe310631843db0fdcdfbe608d68b30dbf52b64f857a51f56589bc9cbaebb66
MD5 a3d1a1b1f849076ffe52d16b4cb69f50
BLAKE2b-256 f1149411c3ecb5db6945043fae861bd4c91df43b0b8a4b8d486d46944cf15833

See more details on using hashes here.

Provenance

The following attestation bundles were made for barkod-0.1.2-cp38-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl:

Publisher: release.yml on mommo-codes/barkod

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file barkod-0.1.2-cp38-abi3-macosx_11_0_arm64.whl.

File metadata

  • Download URL: barkod-0.1.2-cp38-abi3-macosx_11_0_arm64.whl
  • Upload date:
  • Size: 267.9 kB
  • Tags: CPython 3.8+, macOS 11.0+ ARM64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for barkod-0.1.2-cp38-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 1b95db11a42a45e8d2fd3a29c1bb0a9c23753f672615c05bfe3c4a1d60f5aa28
MD5 15b79aee4de26923f0b4c588f7cab741
BLAKE2b-256 005aa733afbcc320607fcf348d5f4b32e8c69db76aa438e88dfd77bc6addf407

See more details on using hashes here.

Provenance

The following attestation bundles were made for barkod-0.1.2-cp38-abi3-macosx_11_0_arm64.whl:

Publisher: release.yml on mommo-codes/barkod

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Release history Release notifications | RSS feed

This release

0.1.2 This release

4 files

0.1.1

4 files

0.1.0

3 files

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