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.1-cp38-abi3-win_amd64.whl (163.3 kB view details)

Uploaded CPython 3.8+Windows x86-64

barkod-0.1.1-cp38-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (306.4 kB view details)

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

barkod-0.1.1-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.1-cp38-abi3-macosx_11_0_arm64.whl (268.1 kB view details)

Uploaded CPython 3.8+macOS 11.0+ ARM64

File details

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

File metadata

  • Download URL: barkod-0.1.1-cp38-abi3-win_amd64.whl
  • Upload date:
  • Size: 163.3 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.1-cp38-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 ed0649331450b5c3874828cf611b6f72f950d20a28e7884edaaa687865ccdaaf
MD5 9b3874e83e8fbfeddad48195916a06b3
BLAKE2b-256 f3b0fce0adf4312fcd60f41bf3c6158fb79d842be42cfc23447715182fe20d87

See more details on using hashes here.

Provenance

The following attestation bundles were made for barkod-0.1.1-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.1-cp38-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for barkod-0.1.1-cp38-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 9c65b5a2439ea210c1c8051f16f52049cad7906b08b26ed7d3f746df170a8faf
MD5 21d59072652ad52b3d2992cde171cf7c
BLAKE2b-256 5904769be0284af0248be6246cc2cce56493c641bd4c47d3e313d75618ae3c68

See more details on using hashes here.

Provenance

The following attestation bundles were made for barkod-0.1.1-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.1-cp38-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for barkod-0.1.1-cp38-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 0db9edd7c20d6313c4c0d85da70e93dbad9619cfc0c9e1d680e42f240b7ab911
MD5 6b5f37257bb459de56eb229d9795d7fb
BLAKE2b-256 acb4dc647fa124a63abc29630f0886a5f75e7547c4960b9821c3a376c6ef1ce0

See more details on using hashes here.

Provenance

The following attestation bundles were made for barkod-0.1.1-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.1-cp38-abi3-macosx_11_0_arm64.whl.

File metadata

  • Download URL: barkod-0.1.1-cp38-abi3-macosx_11_0_arm64.whl
  • Upload date:
  • Size: 268.1 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.1-cp38-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 0c76bca23836ba2a5bcbefb51c0e280969e1462e3a481d087ac7432d74a49fbc
MD5 f0e09d5c1ce38c44ddddd4524b984a00
BLAKE2b-256 a2aa94339ccfd3ace00988e65010dd94a402edebde03f8fa5b13289318b736b6

See more details on using hashes here.

Provenance

The following attestation bundles were made for barkod-0.1.1-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

0.1.2

4 files

This release

0.1.1 This release

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