Create standard barcodes with Python. No external modules needed (optional PIL support included).
Project description
![example_ean13.png](https://bitbucket.org/repo/rXdyBE/images/1631728592-example_ean13.png)
pyBarcode
This library provides a simple way to create barcodes using only the Python standardlib. The barcodes where created as SVG objects.
Report bugs at https://bitbucket.org/whitie/python-barcode/issues/
Requirements
Setuptools/distribute for installation (new in version 0.7beta4)
Python 2.6 or above (including Python 3.x)
On Python 2.6, 3.0, 3.1: argparse (for the commandline script)
Program to open SVG objects (your browser should do it)
Optional: PIL to render barcodes as images (PNG, JPG, …)
Installation
Make sure you have setuptools/distribute installed.
Unpack the downloaded file, cd into the pyBarcode directory and run python setup.py install. Or just copy the barcode dir somewhere in your PYTHONPATH.
The best way is to use pip: pip install pyBarcode.
Provided Barcodes
EAN-8, EAN-13, EAN-14, UPC-A, JAN, ISBN-10, ISBN-13, ISSN, Code 39, Code 128, PZN
Todo
Add documentation
Add more codes
Improve Python 3 support
Add simple GUI
Usage
Interactive:
>>> import barcode >>> barcode.PROVIDED_BARCODES [u'code39', u'code128', u'ean', u'ean13', u'ean8', u'gs1', u'gtin', u'isbn', u'isbn10', u'isbn13', u'issn', u'jan', u'pzn', u'upc', u'upca'] >>> EAN = barcode.get_barcode_class('ean13') >>> EAN <class 'barcode.ean.EuropeanArticleNumber13'> >>> ean = EAN(u'5901234123457') >>> ean <barcode.ean.EuropeanArticleNumber13 object at 0x00BE98F0> >>> fullname = ean.save('ean13_barcode') >>> fullname u'ean13_barcode.svg' # Example with PNG >>> from barcode.writer import ImageWriter >>> ean = EAN(u'5901234123457', writer=ImageWriter()) >>> fullname = ean.save('ean13_barcode') u'ean13_barcode.png' # New in v0.4.2 >>> from StringIO import StringIO >>> fp = StringIO() >>> ean.write(fp) # or >>> f = open('/my/new/file', 'wb') >>> ean.write(f) # PIL (ImageWriter) produces RAW format here # New in v0.5.0 >>> from barcode import generate >>> name = generate('EAN13', u'5901234123457', output='barcode_svg') >>> name u'barcode_svg.svg' # with file like object >>> fp = StringIO() >>> generate('EAN13', u'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:
$ pybarcode{2,3} create "My Text" outfile New barcode saved as outfile.svg. $ pybarcode{2,3} create -t png "My Text" outfile New barcode saved as outfile.png. Try `pybarcode -h` for help.
Changelog
- v0.8:
Code 128 added. Data for charsets and bars moved to subpackage barcode.charsets. Merged in some improvements.
- v0.7:
Fixed some issues with fontsize and fontalignment. Added Python 3 support. It’s not well tested yet, but the tests run without errors with Python 3.3. Commandline script added.
- v0.6:
Changed save and write methods to take the options as a dict not as keyword arguments (fix this in your code). Added option to left align the text under the barcode. Fixed bug with EAN13 generation.
- v0.5.0:
Added new generate function to do all generation in one step. Moved writer from a subpackage to a module (this breaks some existing code). UPC is now rendered as real UPC, not as EAN13 with the leading “0”.
- v0.4.3:
Fixed bug in new write method (related to PIL) and updated docs.
- v0.4.2:
Added write method to support file like objects as target.
- v0.4.1:
Bugfix release. Removed redundancy in input validation. EAN8 was broken. It now works as expected.
- v0.4:
Removed **options from writers __init__ method. These options never had effect. They were always overwritten by default_options. New config option available: text_distance (the distance between barcode and text).
- v0.4b2:
Basic documentation included. The barcode object now has a new attribute called raw to have the rendered output without saving to disk.
- v0.4b1:
Support for rendering barcodes as images is implemented. PIL is required to use it.
- v0.3:
Compression for SVG output now works.
- v0.3b1:
Writer API has changed for simple adding new (own) writers. SVG output is now generated with xml.dom module instead of stringformatting (makes it more robust).
- v0.2.1:
API of render changed. Now render takes keyword arguments instead of a dict.
- v0.2:
More tests added.
- v0.1:
First release.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file python-barcode-0.8.tar.gz
.
File metadata
- Download URL: python-barcode-0.8.tar.gz
- Upload date:
- Size: 224.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 576623588fcc4378909c62c5cd9bda659a26371a691c86d6830067be2e7ad0b1 |
|
MD5 | b57fe4c5a56dc688d58c959c52a98316 |
|
BLAKE2b-256 | 1a25551a3ccae85fc82e85304bd9d7c8ef951d6660a5120f34b7cd6835025762 |
File details
Details for the file python_barcode-0.8-py3-none-any.whl
.
File metadata
- Download URL: python_barcode-0.8-py3-none-any.whl
- Upload date:
- Size: 214.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | eb8c98fc40eeaea3291615474dc826ebae18573ad36c129b8dfdf5482ee4d3e5 |
|
MD5 | 87d09dd22e1b8a97c93c67bc66aa588d |
|
BLAKE2b-256 | 56f9d307e72f7651745fc92fc14332c7e4f50264f236f2c243956bd0af06dd1b |