Skip to main content

A Python package for generating random JAN codes and related product identification codes with valid check digits

Project description

JAN Code Generator

PyPI version License: MIT

A Python package for generating random JAN (Japanese Article Number) codes and related product identification codes with valid check digits.

The check digit calculation follows the standard GS1 algorithm as documented on the GS1 Japan website.

Features

  • Generate random GTIN-13, GTIN-8, GTIN-14, UPC-12, SSCC-18, and GRAI-14 codes
  • Support custom prefix for all code generation functions
  • Generate JAN codes of arbitrary length with random_jan_code
  • Validate JAN/GTIN/UPC codes with is_valid
  • All codes include automatically calculated valid check digits
  • Pure Python implementation with no external dependencies

Installation

Install from PyPI:

pip install jancodegen

Or install from source:

git clone https://github.com/kientt137/jancodegen.git
cd jancodegen
pip install .

Usage

Basic Usage

from jancodegen import jan

# Generate codes with default random values
gtin13 = jan.random_gtin_13()                   # 13-digit GTIN-13 code
upc12 = jan.random_upc_12()                     # 12-digit UPC-12 code
sscc18 = jan.random_sscc_18()                   # 18-digit SSCC-18 code
grai14 = jan.random_grai_14()                   # 14-digit GRAI-14 code
gtin8_prefixed = jan.random_gtin_8("12")        # GTIN-8 starting with '12'
gtin14_prefixed = jan.random_gtin_14("123")     # GTIN-14 starting with '123'

# Generate arbitrary length JAN code
custom_jan_prefixed = jan.random_jan_code(13, "12345") # 13-digit JAN code starting with '12345'

# Validate codes
assert jan.is_valid(gtin13)

Code Formats

Format Length Description Prefix (default)
GTIN-13 13 digits Global Trade Item Number Customizable
GTIN-8 8 digits Global Trade Item Number (short) Customizable
GTIN-14 14 digits Global Trade Item Number (carton) '1' or custom
UPC-12 12 digits Universal Product Code Customizable
SSCC-18 18 digits Serial Shipping Container Code '0' or custom
GRAI-14 14 digits Global Returnable Asset Identifier '0' or custom
JAN (custom) 4-32 digits Arbitrary-length JAN code Customizable

Requirements

  • Python 3.7 or higher
  • No external dependencies required

Development

Running Tests

pip install pytest
python -m pytest tests/

Building the Package

python setup.py sdist bdist_wheel

License

This project is licensed under the MIT License

Issues

If you find any bugs or have suggestions for improvements, please open an issue on GitHub.

Project details


Download files

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

Source Distribution

jancodegen-1.0.2.tar.gz (5.5 kB view details)

Uploaded Source

Built Distribution

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

jancodegen-1.0.2-py3-none-any.whl (4.4 kB view details)

Uploaded Python 3

File details

Details for the file jancodegen-1.0.2.tar.gz.

File metadata

  • Download URL: jancodegen-1.0.2.tar.gz
  • Upload date:
  • Size: 5.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.0

File hashes

Hashes for jancodegen-1.0.2.tar.gz
Algorithm Hash digest
SHA256 d701ef2d5e565e86537e5b0f5960e107700665fab07578e0243af193918dfca3
MD5 89ca9c4b686a104a8cb820a6b1261c93
BLAKE2b-256 3ae8d0f99aec25e568f0267555f198e76c36b9429e1542661fe498b91fd1104d

See more details on using hashes here.

File details

Details for the file jancodegen-1.0.2-py3-none-any.whl.

File metadata

  • Download URL: jancodegen-1.0.2-py3-none-any.whl
  • Upload date:
  • Size: 4.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.0

File hashes

Hashes for jancodegen-1.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 14abb3d8b18ef5d8d5fa36ef92d5b3352997894169e29c8190afbbf91592fab7
MD5 f2d3f6943b7b81784d52fac9e63ce74d
BLAKE2b-256 bf4439e5b329e1bf34d5489c58eebf24cf518f22aaf741ed9201841f25374147

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page