| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Name | Name | Last commit date | ||
|---|---|---|---|---|
This library provides a simple way to create barcodes using only the Python standard lib. The barcodes are created as SVG objects.
Full documentation is published at http://python-barcode.rtfd.io/
Please report any bugs at https://github.com/WhyNotHugo/python-barcode/issues
The best way is to use pip: pip install python-barcode. Don't forget to add this to our app's dependencies.
If you'll be exporting to images (eg: not just SVG), you'll need additional optional dependencies, so run: pip install python-barcode[images].
PRs for other code formats are welcome!
Programmatic:
from barcode import EAN13
from barcode.writer import ImageWriter
# print to a file-like object:
rv = BytesIO()
EAN13(str(100000902922), writer=ImageWriter()).write(rv)
# or sure, to an actual file:
with open('somefile.jpeg', 'wb') as f:
EAN13('100000011111', writer=ImageWriter()).write(f)
Interactive:
>>> import barcode
>>> barcode.PROVIDED_BARCODES
['code39', 'code128', 'ean', 'ean13', 'ean8', 'gs1', 'gtin',
'isbn', 'isbn10', 'isbn13', 'issn', 'jan', 'pzn', 'upc', 'upca']
>>> EAN = barcode.get_barcode_class('ean13')
>>> EAN
<class 'barcode.ean.EuropeanArticleNumber13'>
>>> ean = EAN('5901234123457')
>>> ean
<barcode.ean.EuropeanArticleNumber13 object at 0x00BE98F0>
>>> fullname = ean.save('ean13_barcode')
>>> fullname
'ean13_barcode.svg'
# Example with PNG
>>> from barcode.writer import ImageWriter
>>> ean = EAN('5901234123457', writer=ImageWriter())
>>> fullname = ean.save('ean13_barcode')
'ean13_barcode.png'
# New in v0.4.2
>>> from io import BytesIO
>>> fp = BytesIO()
>>> ean.write(fp)
# or
>>> f = open('/my/new/file', 'wb')
>>> ean.write(f) # Pillow (ImageWriter) produces RAW format here
>>> from barcode import generate
>>> name = generate('EAN13', '5901234123457', output='barcode_svg')
>>> name
'barcode_svg.svg'
# with file like object
>>> fp = BytesIO()
>>> generate('EAN13', '5901234123457', writer=ImageWriter(), output=fp)
>>>
Now open ean13_barcode.[svg|png] in a graphic app or simply in your browser and see the created barcode. That's it.
Commandline:
`$ python-barcode create "123456789000" outfile -b ean --text "text to appear under barcode" ` New barcode saved as outfile.svg. # The following will not work if Pillow is not installed (Pillow is required for exporting to images instead of SVG). $ python-barcode create -t png "My Text" outfile New barcode saved as outfile.png. Try `python-barcode -h` for help.
This project is a fork of pyBarcode, which, apparently, is no longer maintained. v0.8.0 is our first release, and is the latest master from that parent project.
| Back | FazBrowse Home | New Git URL |