Pybarcode Documentation: Release 0.13.1
Pybarcode Documentation: Release 0.13.1
Release 0.13.1
Thorsten Weimann
1 Contents 3
1.1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
1.2 Create barcodes from the commandline . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4
1.3 Provided barcodes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4
1.4 python-barcode Writer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10
1.5 License . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14
Index 17
i
ii
pyBarcode Documentation, Release 0.13.1
Contents 1
pyBarcode Documentation, Release 0.13.1
2 Contents
CHAPTER 1
Contents
1.1 Introduction
This package was created to have barcodes available with pure-python. Pillow is required for exporting images (png,
jpg), although not for SVGs.
All you need to create a barcode is to know the system (EAN, UPC, . . . ) and the code (e.g. for EAN-13:
123456789102). As you see, you do not need the checksum, it will be calculated automatically. In some systems
(Code 39) the checksum is optional, there you can give the add_checksum keyword argument (default is True).
To generate barcodes as SVG objects, you can use the default writer (simply not specify a writer).
Quick example:
Now you have ean13.svg and the compressed ean13.svgz in your current working directory. Open it and see the result.
3
pyBarcode Documentation, Release 0.13.1
1.3.1 Code 39
4 Chapter 1. Contents
pyBarcode Documentation, Release 0.13.1
render(writer_options=None, text=None)
Renders the barcode using self.writer.
Parameters
writer_options [Dict] Options for self.writer, see writer docs for details.
text [str] Text to render under the barcode.
Returns Output of the writers render method.
Class Hirarchy
Barcode Code39
Class Hirachy
Barcode Code128
1.3.3 PZN
barcode.codex.PZN
alias of barcode.codex.PZN7
Class Hirarchy
1.3.4 EAN-13
6 Chapter 1. Contents
pyBarcode Documentation, Release 0.13.1
Class Hirarchy
Barcode EuropeanArticleNumber13
1.3.5 EAN-8
Class Hirarchy
1.3.6 JAN
Class Hirarchy
1.3.7 ISBN-13
Class Hirarchy
1.3.8 ISBN-10
8 Chapter 1. Contents
pyBarcode Documentation, Release 0.13.1
Class Hirarchy
1.3.9 ISSN
Class Hirarchy
1.3.10 UPC-A
Class Hirarchy
Barcode UniversalProductCodeA
All writer take the following options (specified as keyword arguments to Barcode.save(filename, options) or set via
Writer.set_options(options), where options is a dictionary where keys are option names and values are option values
to be set).
Note: See the documentation of the specific writer for special options, only available for this writer.
Common Options:
10 Chapter 1. Contents
pyBarcode Documentation, Release 0.13.1
text_distance Distance between the barcode and the text under it in mm as float. Defaults to 5.0.
background The background color of the created barcode as string. Defaults to white.
foreground The foreground and text color of the created barcode as string. Defaults to black.
New in version 0.6.
center_text If true (the default) the text is centered under the barcode else left aligned.
Note: Some barcode classes change the above defaults to fit in some kind of specification.
1.4.2 Writers
python-barcode SVGWriter
Special Options
In addition to the common writer options you can give the following special option.
Special Option:
compress Boolean value to output a compressed SVG object (.svgz). Defaults to False.
python-barcode ImageWriter
Special Options
In addition to the common writer options you can give the following special options.
Special Options:
format The image file format as string. All formats supported by Pillow are valid (e.g. PNG, JPEG,
BMP, . . . ). Defaults to PNG.
dpi DPI as integer to calculate the image size in pixel. This value is used for all mm to px calculations.
Defaults to 300.
To create your own writer, inherit from barcode.writer.BaseWriter. In your __init__ method call BaseWriter’s __init__
and give your callbacks for initialize(raw_code), paint_module(xpos, ypos, width, color), paint_text(xpos, ypos) and
finish().
Now instatiate a new barcode and give an instance of your new writer as argument. If you now call render on the
barcode instance your callbacks get called.
12 Chapter 1. Contents
pyBarcode Documentation, Release 0.13.1
save(filename, output)
Saves the rendered output to filename.
Parameters
filename [String] Filename without extension.
output [String] The rendered output.
Returns The full filename with extension.
Return type String
set_options(options)
Sets the given options as instance attributes (only if they are known).
Parameters
options [Dict] All known instance attributes and more if the childclass has defined them
before this call.
Return type None
class barcode.writer.ImageWriter(format=’PNG’, mode=’RGB’)
save(filename, output)
Saves the rendered output to filename.
Parameters
filename [String] Filename without extension.
output [String] The rendered output.
Returns The full filename with extension.
Return type String
write(content, fp: BinaryIO)
Write content into a file-like object.
Content should be a barcode rendered by this writer.
class barcode.writer.SVGWriter
save(filename, output)
Saves the rendered output to filename.
Parameters
filename [String] Filename without extension.
output [String] The rendered output.
Returns The full filename with extension.
Return type String
write(content, fp: BinaryIO)
Write content into a file-like object.
Content should be a barcode rendered by this writer.
1.5 License
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
14 Chapter 1. Contents
Python Module Index
b
barcode.writer, 12
15
pyBarcode Documentation, Release 0.13.1
B I
barcode.writer (module), 12 ImageWriter (class in barcode.writer), 13
BaseWriter (class in barcode.writer), 12 InternationalStandardBookNumber10 (class
build() (barcode.ean.EuropeanArticleNumber13 in barcode.isxn), 8
method), 6 InternationalStandardBookNumber13 (class
build() (barcode.ean.EuropeanArticleNumber8 in barcode.isxn), 8
method), 7 InternationalStandardSerialNumber (class
build() (barcode.upc.UniversalProductCodeA in barcode.isxn), 9
method), 9
J
C JapanArticleNumber (class in barcode.ean), 8
calculate_checksum() (bar-
code.ean.EuropeanArticleNumber13 method), P
6 PZN (in module barcode.codex), 6
calculate_checksum() (bar-
code.upc.UniversalProductCodeA method), R
9 register_callback() (barcode.writer.BaseWriter
calculate_size() (barcode.writer.BaseWriter method), 12
method), 12 render() (barcode.codex.Code128 method), 5
Code128 (class in barcode.codex), 5 render() (barcode.codex.Code39 method), 4
Code39 (class in barcode.codex), 4 render() (barcode.ean.EuropeanArticleNumber13
method), 7
E render() (barcode.upc.UniversalProductCodeA
EuropeanArticleNumber13 (class in barcode.ean), method), 10
6 render() (barcode.writer.BaseWriter method), 12
EuropeanArticleNumber8 (class in barcode.ean),
7 S
save() (barcode.writer.BaseWriter method), 12
G save() (barcode.writer.ImageWriter method), 13
get_fullcode() (barcode.codex.Code128 method), save() (barcode.writer.SVGWriter method), 13
5 set_options() (barcode.writer.BaseWriter method),
get_fullcode() (barcode.codex.Code39 method), 4 13
get_fullcode() (bar- SVGWriter (class in barcode.writer), 13
code.ean.EuropeanArticleNumber13 method),
6 T
get_fullcode() (bar- to_ascii() (barcode.ean.EuropeanArticleNumber13
code.upc.UniversalProductCodeA method), method), 7
9 to_ascii() (barcode.upc.UniversalProductCodeA
method), 10
17
pyBarcode Documentation, Release 0.13.1
U
UniversalProductCodeA (class in barcode.upc), 9
W
write() (barcode.writer.ImageWriter method), 13
write() (barcode.writer.SVGWriter method), 13
writer, 10
writer_options, 10
18 Index