Giter Club home page Giter Club logo

python-barcode's Introduction

python-barcode

CI status

documentation

version on pypi

downloads

licence

python-barcode provides a simple way to create barcodes in Python.

There are no external dependencies when generating SVG files. Pillow is required for generating images (e.g.: PNGs).

Support Python 3.8 to 3.12.

python-barcode

Documentation

Full documentation is published at http://python-barcode.rtfd.io/

You can build the documentation locally using make -C docs html.

Licence

python-barcode is licensed under the MIT licence. See LICENCE for details.

python-barcode's People

Contributors

akx avatar alanswenson avatar audoh-tickitto avatar bjornarle avatar brvoisin avatar d-r-jenkins avatar enorms avatar fostermaier avatar fra87 avatar heuer avatar iconberg avatar jay51 avatar jdhaene avatar jgbishop avatar lasley avatar maruta avatar mdziwny avatar mibou avatar pre-commit-ci[bot] avatar roth-a avatar smurfix avatar tendervittles avatar tetsutalow avatar thanegill avatar traversi avatar whitie avatar whynothugo avatar x-n0 avatar xcodinas avatar yourcelf avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

python-barcode's Issues

When using an ImageWriter with 'Code39' the add_checksum option is ignored

When using the generator function to create a 'Code39' barcode, the writer_options={'add_checksum': False} is ignored.

The addition of the check digit happens during the class init which hasn't received the writer_options.

I have a fix for this by moving the check into the render function and adding an instance variable to track when it has been added. (I wasn't sure if the render function could end up being called more than once and didn't want additional check digits adding.

Will create a PR for the fix.

Vertical white space is not configurable

There's a fixed 1 unit of white space added above and below bar codes. I'd love to be able to adjust this; seems like it would be great as a writer option.

Should be simple and quick to implement.

Unwanted behaviour of the no_checksum option for EuropeanArticleNumber13

If the no_checksum option is passed, A 13 digits code should be accepted as it is.
At the moment, the last digit is replaced by a 0 and it cannot be otherwise:

digits = 12
ean = ean[:self.digits]
# Add a thirteen char if given in parameter,
# otherwise pad with zero
self.ean =  '{0}{1}'.format( ean, ean[self.digits] if len(ean) > self.digits else 0)

len(ean) > self.digits is never going to happen

TypeError: string argument expected, got 'bytes' ?

the barcode run error in python3.6

import barcode
import io
from barcode.writer import ImageWriter
import traceback

fp = io.StringIO()
barcode.generate('gs1_128', 'iloveyou', writer=ImageWriter(), output=fp)

Traceback (most recent call last):
File "C:\Users\jekoie\AppData\Local\Programs\Python\Python36-32\lib\site-packages\IPython\core\interactiveshell.py", line 3326, in run_code
exec(code_obj, self.user_global_ns, self.user_ns)
File "", line 7, in
barcode.generate('gs1_128', 'iloveyou', writer=ImageWriter(), output=fp)
File "C:\Users\jekoie\AppData\Local\Programs\Python\Python36-32\lib\site-packages\barcode_init_.py", line 80, in generate
barcode.write(output, options, text)
File "C:\Users\jekoie\AppData\Local\Programs\Python\Python36-32\lib\site-packages\barcode\base.py", line 90, in write
output.save(fp, format=self.writer.format)
File "C:\Users\jekoie\AppData\Local\Programs\Python\Python36-32\lib\site-packages\PIL\Image.py", line 2088, in save
save_handler(self, fp, filename)
File "C:\Users\jekoie\AppData\Local\Programs\Python\Python36-32\lib\site-packages\PIL\PngImagePlugin.py", line 807, in _save
TypeError: string argument expected, got 'bytes'

the python3.6 pillow treat raw code as bytes, but barcode treat as string, so it raise error?
another issue is how can i create a barcode only show graph without number under the graph??

text above the barcode

Hello, I would like to know if there is the possibility of put a text above the bar code?

text here
||IIIIIIllllllllII||
12345679

Thanks for your help.

UPCA header file is not working.

I am trying to create barcodes using PyBarcode for UPCA instead it is creating EAN13 code in .png format. How to get .it in jpg format.

import barcode
from barcode.writer import ImageWriter
from barcode import UPCA

upca_get_code = UPCA('8280984033', writer=ImageWriter, make_ean=True)
file = upca_get_code.save('UPC_BARCODE')

Got different number

name = generate('EAN13', '1234567890123', output='barcode_svg')

This gives the barcode of '1234567890128'.
Too spare time, the last number is an eight instead of a three. How is this possible?
Even something simple as '55555555555555' changes the last number to a zero: '55555555555550'.

Why is this happening? I definitely need the last number to work to read the right codes, how to fix this?

I have an 9 digit number which I'd just like to turn into a barcode, I thought of using EAN13, multiplying the number by 1000 and making a string out of it, but while doing this it adds random numbers too the last four digits instead of zero's when a barcode is formed. I really don't get why?

Just checked and found that this problem is the case for EAN13, when using gs1_128 I just get the zero's that were supposed to be there. Anyone knows anything more about this?

Poor choice of default DPI and module width

I am using the library for generating Code128 barcodes which will later be integrated in another image.

Without setting any writer options the default values for the ImageWriter are: DPI=300 and ModuleWidth=0.2 (labeled mm in the docs but that is not correct, as 0.2 results in 2mm).
These settings do not go well together, as with 300dpi one dot has the size of 0.8466mm - so the default module width would equal 2.36dots.

I did not have a look into the rounding but I can confirm, that some barcodes I generate can not be read with these settings. If I set the module width to a number that results in an integer number of dots (e.g. 0.8466mm or multiples thereof) I am able to scan these barcodes.

In general one could ask, why it uses mm as a unit at all and not pixels or at least offers the possibility to set the module width in pixels without using DPI.

Comment doesn't display package version

When I write a Code128 barcode in Python3, I get the following:

<svg height="23.000mm" version="1.1" width="29.000mm" xmlns="http://www.w3.org/2000/svg">
    <!--Autogenerated with python-barcode <module 'barcode.version' from '[...]/lib/python3.6/site-packages/barcode/version.py'>-->
    <g id="barcode_group">...

It should probably be more like

<svg height="23.000mm" version="1.1" width="29.000mm" xmlns="http://www.w3.org/2000/svg">
    <!--Autogenerated with python-barcode v0.8.1-->
    <g id="barcode_group">...

The problem seems to be that from barcode import version on line 9 of barcode.writer imports the barcode.version module, rather than importing the version object from barcode.__init__.

Newline "\n" is not interpreted

For instance

from barcode import get_barcode_class
CODE128 = get_barcode_class('code128')
code128 = CODE128('12345')
code128.save('test', options={'human': 'This is a \n test'})

test

The newline character "\n" has no effect.

GS1 barcode pulling ISBN instead

Here is my code:

 import barcode
 from barcode.writer import ImageWriter
 varGS1 = barcode.get_barcode_class('gs1')
 varGS1out = varGS1(u'42053005383691149014', writer=ImageWriter)
 fullname = varGS1out.save('C:\\Users\\PaulPers\\Desktop\\GS1_barcode')

and I get the following error:

Traceback (most recent call last):
File "", line 5, in
File "C:\Users\PaulPers\AppData\Roaming\Python\Python37\site-packages\barcode\isxn.py", line 50, in init
raise WrongCountryCodeError('ISBN must start with 978 or 979.')
barcode.errors.WrongCountryCodeError: ISBN must start with 978 or 979.

Thank you.

TypeError running commandline example

Running Python 3.6.5. I tested the command-line example with ended with the following error.
python-barcode create "My Text" outfile

Traceback (most recent call last):
  File "/anaconda3/bin/python-barcode", line 10, in <module>
    sys.exit(main())
  File "/anaconda3/lib/python3.6/site-packages/barcode/pybarcode.py", line 119, in main
    func(args, parser)
  File "/anaconda3/lib/python3.6/site-packages/barcode/pybarcode.py", line 63, in create_barcode
    args.text)
  File "/anaconda3/lib/python3.6/site-packages/barcode/__init__.py", line 73, in generate
    barcode = get(name, code, writer, options)
  File "/anaconda3/lib/python3.6/site-packages/barcode/__init__.py", line 61, in get
    return barcode(code, writer, **options)
TypeError: __init__() got an unexpected keyword argument 'compress'

Any suggestions?

Unable to import barcode

i already install barcode module from official python site like "pip install python-barcode". but whenever i write a code on text editor like 1-Visual Studio 2-SubLime 3-Pycharm theirs an error pop up and it's says "Unable to import 'barcode' pylint(input-error)[1,1]"

e.g. barcode.default_writer_options['quiet_zone'] = 10 isn´t working properly

Hello,
I´m trying to set the quiet_zone very low. e.g. 0.6.

I fixed the order in the base.py render function:
Line 105 and 106:

Removed this:
options = Barcode.default_writer_options.copy()
options.update(writer_options or {})
Instead I added this:
writer_options.update(Barcode.default_writer_options)
options = writer_options.copy()

Now its working. I´m new to github. Dont know how to make a pull request

can not install it in win10 or centos7

I download the code from the trunk line and install it with 'python setup.py install' into my win10 and centos7. all of them are failed.
"ImportError: No module named pathlib" is occurred first, after I fix it by 'pip install pathlib',

Traceback (most recent call last):
  File ".\setup.py", line 17, in <module>
    long_description=Path('README.rst').read_text(),
AttributeError: 'WindowsPath' object has no attribute 'read_text'

occurred in windows and

Traceback (most recent call last):
  File "setup.py", line 17, in <module>
    long_description=Path('README.rst').read_text(),
AttributeError: 'PosixPath' object has no attribute 'read_text'

occurred in centos7.

Code39 and Code128 Missing kwarg Default

For barcodes that are not code39 and code128, the user is able to call the render function without specifying 'writer_options'. This is because that argument is set equal to None by default in 'base.py'

However, in 'codex.py', both classes Code39 and Code128 override render(), but do not set 'writer_options' equal to None by default.

Proposed Change: Use def render(self, writer_options=None, text=None): instead of def render(self, writer_options, text=None): for Code39 and Code128.

no module name error

i am installed successfully the python-barcode packages. but i get the no moduled name error when i use the module.
"ModuleNotFoundError: No module named 'barcode'"

Passing writer_options with generate()

I'm calling generate() function to create a code128 barcode, and I need to pass custom writer_options payload. Here is the code fragment:

writer_options = {
    'module_width': 0.3,
    'module_height': 25.0,
    'quiet_zone': 1,
    'font_size': 10,
    'text_distance': 0,
    'background': 'white',
    'foreground': 'black',
    'write_text': True,
    'text': '',
}
name = generate('code128', foo, output=f"barcode_{foo}", text=' ', writer=ImageWriter(), writer_options=writer_options)

This code gives me the following error message:

Traceback (most recent call last):
  File "gen_barcode_foreign.py", line 55, in <module>
    name = generate('code128', tracking, output=f"barcode_{tracking}", text=' ', writer=ImageWriter(), writer_options=writer_options)
  File "d:\python_test\barcodes\venv\lib\site-packages\barcode\__init__.py", line 73, in generate
    barcode = get(name, code, writer, options)
  File "d:\python_test\barcodes\venv\lib\site-packages\barcode\__init__.py", line 61, in get
    return barcode(code, writer, **options)
TypeError: __init__() got an unexpected keyword argument 'module_width'

I tried to edit __init__.py, changing the line #61 from return barcode(code, writer, **options) to return barcode(code, writer), and it helped, generate() now works fine.

Not sure if this is the correct way to solve this issue though.

EAN-13/GTIN-13 barcodes don't contain grouping

According to the specs I've found, GTIN-13/EAN-13 barcodes must contain the grouping most commonly found on printed barcodes, i.e. the first character is outside of the code area, and the remainder is in two groups with elongated bars separating the groups.

Is there any support for this planned? How about the '>' mark for silent areas?

Transparent ImageWriter background

I love this library, and was wondering whether there were any plans for allowing transparent backgrounds as a option for the background attribute in barcode.writer.ImageWriter, effectively allowing for png barcodes with transparent backgrounds that are easy to paste over other images in PIL post-processing. This could be implemented by allowing for rgba(r,g,b,a) as an input instead of just white, black, orange, etc.:

options={
            "background":"rgba(0,0,0,0)",
            }

Thanks.

Option to suppress check digit?

Is there an option to suppress the check digit? I'm testing with the samples on the homepage, substituting in type code39, if that matters.

TIA

Cannot save as png after packaging into exe file

微信截图_20200426105205

Traceback (most recent call last):
  File "site-packages\PIL\ImageFont.py", line 186, in __init__
UnicodeDecodeError: 'ascii' codec can't decode byte 0xe5 in position 9: ordinal not in range(128)

This error occurs under python3.6, how to solve it

Installation on Windows fails

On Windows 7 x64, Python 2.7 64-bit,

pip install python-barcode

gives

  Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "c:\users\blah\appdata\local\temp\pip-build-q_pfeu\python-barcode\se
  tup.py", line 18, in <module>
  long_description=Path('README.rst').read_text(),
  AttributeError: 'WindowsPath' object has no attribute 'read_text'

Would you have any idea?

Thank you in advance.

Commandline usage fails with, AttributeError: module 'barcode' has no attribute '__description__'

Installed python-barcode with, pip3.6 install python-barcode
Command-line usage fails as follows:

Traceback (most recent call last):
  File "/usr/local/bin/python-barcode", line 11, in <module>
    sys.exit(main())
  File "/usr/local/lib/python3.6/site-packages/barcode/pybarcode.py", line 82, in main
    description=barcode.__description__, epilog=' '.join(msg)
AttributeError: module 'barcode' has no attribute '__description__'```

Example in readme does not function

This section:

Commandline:
$ pybarcode create "My Text" outfile
New barcode saved as outfile.svg.
Try 'pybarcode -h' for help.

Results in the error can't open file 'pybarcode':

$ python3 pybarcode create "My Text" outfile
/usr/local/Cellar/python/3.7.2_2/Frameworks/Python.framework/Versions/3.7/Resources/Python.app/Contents/MacOS/Python: can't open file 'pybarcode': [Errno 2] No such file or directory

Add Full ASCII support for Code39

Right now, there is limited ASCII support with Code39.

For example, trying to include a _ in a barcode will produce the error: IllegalCharacterError: The following characters are not valid for Code 39: _

How to remove the text

Hi i would like to know how to remove the text from under the barcodes, to have only the barcode, no text.

Missing changelog for 0.10.0

I see version 0.10.0 has been uploaded to pypi but the changelog does not list the changes in this version.

IIUC this release contains support for the gs1-128 barcodes. Does it?

generating long barcode

I'm trying to generate 43 digits barcode, but the barcode generated is shorter, 35 digits.
how can I generate the entire string?

this is the code I use:
mystr="0024591002013166513116148610000000100005891"
EAN = barcode.get_barcode_class('code128')
ean = EAN(mystr)

arel

no such modules

what to do now ? as there is no such modules.
I tried pip install pyBarcode but nothing happend

How to read the barcodes?

This looks like what I need. However if I wanted to scan this barcode and read into my program to see what it is, is this possible?

Using 'raw' without using 'save' gives no output

I think the title explains it all.

If I try to use .raw to server an SVG barcode without using .save first, I get an empty output...

Example:
Trying to serve this in my django project:

class APIBarcode(View):

    def get(self, request, *args, **kwargs):
        uuid = request.GET.get('uuid')
        C39 = barcode.get_barcode_class('code39')
        toserve = C39(uuid)
        toserve.save('c39code')
        return HttpResponse(toserve.raw, content_type="image/svg+xml")

Gives the following output:
image

But serving this:

class APIBarcode(View):

    def get(self, request, *args, **kwargs):
        uuid = request.GET.get('uuid')
        C39 = barcode.get_barcode_class('code39')
        toserve = C39(uuid)
        # toserve.save('c39code')
        return HttpResponse(toserve.raw, content_type="image/svg+xml")

Gives the following output:

image

If someone can point me to where I should be looking I would gladly attempt to fix it!

barcode.get writer_options not used

def get(name, code=None, writer=None, options=None, writer_options=None):

does not pass writer_options anywhere and the documentation does not speak about it

TypeError running # Example with PNG in usage guide

I'm running Python 3.5.5. A subsection of the usage guide:

import barcode
from barcode.writer import ImageWriter
EAN = barcode.get_barcode_class('code128')
ean = EAN(u'5901234123457', writer=ImageWriter())

...gives me the following error:

---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-67-21778fac1b87> in <module>()
----> 1 ean = EAN(u'5901234123457', writer=ImageWriter())

TypeError: 'NoneType' object is not callable

Am I doing something wrong?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.