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

Uploaded CPython 3.8+Windows x86-64

barkod-0.1.0-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.0-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.0-cp38-abi3-win_amd64.whl.

File metadata

  • Download URL: barkod-0.1.0-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.0-cp38-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 c07153c700ae847c52e9609a1a002502501f3f657a47853696ada437f87b69d4
MD5 caf34b3cf0d2862357faf32cad787014
BLAKE2b-256 b22453cd49292d0b0dd2a2192ef2a89ad5da320e4fe997dcfb52ab2b40f59bff

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for barkod-0.1.0-cp38-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 2ada92349cfaebb0ec81a46202006af61fb525ddecf5a73c6e6890a0b2828432
MD5 cb5ea8472e0646d21635baf638ea1cb9
BLAKE2b-256 f0b134b25da4bb260a32de648a8567fda9e8d109839e6f911c49b7678d219181

See more details on using hashes here.

Provenance

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

File metadata

  • Download URL: barkod-0.1.0-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.0-cp38-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 aa3bd6f313218291015b5ef6f47faf8bcf8965fb5ccc02bd476b2ebf434b6584
MD5 5f3a0d01db5c7f10caf0b54c683655dc
BLAKE2b-256 6f460139c7bb31e8d991f8919e4c6a52cf8177c50b9ee7faedb2ec34d699565c

See more details on using hashes here.

Provenance

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

0.1.1

4 files

This release

0.1.0 This release

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