Segno package

Module contents

QR Code and Micro QR Code implementation.

“QR Code” and “Micro QR Code” are registered trademarks of DENSO WAVE INCORPORATED.

segno.make(content, error=None, version=None, mode=None, mask=None, encoding=None, eci=False, micro=None, boost_error=True)

Creates a (Micro) QR Code.

This is main entry point to create QR Codes and Micro QR Codes.

Aside from content, all parameters are optional and an optimal (minimal) (Micro) QR Code with a maximal error correction level is generated.

Parameters:
  • content (str, int, bytes) – The data to encode. Either a Unicode string, an integer or bytes. If bytes are provided, the encoding parameter should be used to specify the used encoding.
  • error (str or None) –

    Error correction level. If None (default), error correction level L is used (note: Micro QR Code version M1 does not support any error correction. If an explicit error correction level is used, a M1 QR Code won’t be generated). Valid values: None (allowing generation of M1 codes or use error correction level “L” or better see boost_error), “L”, “M”, “Q”, “H” (error correction level “H” isn’t available for Micro QR Codes).

    Error correction level Error correction capability
    L (Segno’s default unless version M1) recovers 7% of data
    M recovers 15% of data
    Q recovers 25% of data
    H (not available for Micro QR Codes) recovers 30% of data

    Higher error levels may require larger QR Codes (see also version parameter).

    The error parameter is case insensitive.

    See also the boost_error parameter.

  • version (int, str or None) – QR Code version. If the value is None (default), the minimal version which fits for the input data will be used. Valid values: “M1”, “M2”, “M3”, “M4” (for Micro QR Codes) or an integer between 1 and 40 (for QR Codes). The version parameter is case insensitive.
  • mode (str or None) –

    “numeric”, “alphanumeric”, “byte”, or “kanji”. If the value is None (default) the appropriate mode will automatically be determined. If version refers a to Micro QR Code, this function may raise a ModeError if the provided mode is not supported.

    Mode (Micro) QR Code Version
    numeric 1 - 40, M1, M2, M3, M4
    alphanumeric 1 - 40, M2, M3, M4
    byte 1 - 40, M3, M4
    kanji 1 - 40, M3, M4

    The mode parameter is case insensitive.

  • mask (int or None) – Data mask. If the value is None (default), the appropriate data mask is chosen automatically. If the mask parameter is provided, this function may raise a MaskError if the mask is invalid.
  • encoding (str or None) – Indicates the encoding in mode “byte”. By default (encoding is None) the implementation tries to use the standard conform ISO/IEC 8859-1 encoding and if it does not fit, it will use UTF-8. Note that no ECI mode indicator is inserted by default (see eci). The encoding parameter is case insensitive.
  • eci (bool) – Indicates if binary data which does not use the default encoding (ISO/IEC 8859-1) should enforce the ECI mode. Since a lot of QR Code readers do not support the ECI mode, this feature is disabled by default and the data is encoded in the provided encoding using the usual “byte” mode. Set eci to True if an ECI header should be inserted into the QR Code. Note that the implementation may not know the ECI designator for the provided encoding and may raise an exception if the ECI designator cannot be found. The ECI mode is not supported by Micro QR Codes.
  • micro (bool or None) – If version is None (default) this parameter can be used to allow the creation of a Micro QR Code. If set to False, a QR Code is generated. If set to None (default) a Micro QR Code may be generated if applicable. If set to True the algorithm generates a Micro QR Code or raises an exception if the mode is not compatible or the content is too large for Micro QR Codes.
  • boost_error (bool) – Indicates if the error correction level may be increased if it does not affect the version (default: True). If set to True, the error parameter is interpreted as minimum error level. If set to False, the resulting (Micro) QR Code uses the provided error level (or the default error correction level, if error is None)
Raises:

QRCodeError: In case of a problem. In fact, it’s more likely that a derived exception is thrown: ModeError: In case of problems with the mode (i.e. invalid mode or invalid mode / version combination. VersionError: In case the version is invalid or the micro parameter contradicts the provided version. ErrorLevelError: In case the error level is invalid or the error level is not supported by the provided version. DataOverflowError: In case the data does not fit into a (Micro) QR Code or it does not fit into the provided version. MaskError: In case an invalid data mask was specified.

Return type:

QRCode

segno.make_qr(content, error=None, version=None, mode=None, mask=None, encoding=None, eci=False, boost_error=True)

Creates a QR Code (never a Micro QR Code).

See make() for a description of the parameters.

Return type:QRCode
segno.make_micro(content, error=None, version=None, mode=None, mask=None, encoding=None, boost_error=True)

Creates a Micro QR Code.

See make() for a description of the parameters.

Note: Error correction level “H” isn’t available for Micro QR Codes. If used, this function raises a segno.ErrorLevelError.

Return type:QRCode
segno.make_sequence(content, error=None, version=None, mode=None, mask=None, encoding=None, boost_error=True, symbol_count=None)

Creates a sequence of QR Codes using the Structured Append mode.

If the content fits into one QR Code and neither version nor symbol_count is provided, this function may return a sequence with one QR Code which does not use the Structured Append mode. Otherwise a sequence of 2 .. n (max. n = 16) QR Codes is returned which use the Structured Append mode.

The Structured Append mode allows to split the content over a number (max. 16) QR Codes.

The Structured Append mode isn’t available for Micro QR Codes, therefor the returned sequence contains QR Codes, only.

Since this function returns an iterable object, it may be used as follows:

for i, qrcode in enumerate(segno.make_sequence(data, symbol_count=2)):
     qrcode.save('seq-%d.svg' % i, scale=10, color='darkblue')

The number of QR Codes is determined by the version or symbol_count parameter.

See make() for a description of the other parameters.

Parameters:symbol_count (int) – Number of symbols.
Return type:QRCodeSequence
class segno.QRCode(code)

Represents a (Micro) QR Code.

matrix = None

Returns the matrix.

Return type:tuple of bytearray instances.
mask = None

Returns the data mask pattern reference

Return type:int
version

(Micro) QR Code version. Either a string (“M1”, “M2”, “M3”, “M4”) or an integer in the range of 1 .. 40.

Return type:str or int
error

Error correction level; either a string (“L”, “M”, “Q”, “H”) or None if the QR Code provides no error correction (Micro QR Code version M1)

Return type:str
mode

String indicating the mode (“numeric”, “alphanumeric”, “byte”, “kanji”). May be None if multiple modes are used.

Return type:str or None
designator

Returns the version and error correction level as string V-E where V represents the version number and E the error level.

Return type:str
default_border_size

Indicates the default border size aka quiet zone.

QR Codes have a quiet zone of four light modules, while Micro QR Codes have a quiet zone of two light modules.

Return type:int
is_micro

Indicates if this QR Code is a Micro QR Code

Return type:bool
symbol_size(scale=1, border=None)

Returns the symbol size (width x height) with the provided border and scaling factor.

Parameters:
  • scale (int or float) – Indicates the size of a single module (default: 1). The size of a module depends on the used output format; i.e. in a PNG context, a scaling factor of 2 indicates that a module has a size of 2 x 2 pixel. Some outputs (i.e. SVG) accept floating point values.
  • border (int) – The border size or None to specify the default quiet zone (4 for QR Codes, 2 for Micro QR Codes).
Return type:

tuple (width, height)

matrix_iter(scale=1, border=None, verbose=False)

Returns an iterator over the matrix which includes the border.

The border is returned as sequence of light modules. Dark modules are reported as 0x1, light modules have the value 0x0.

The following example converts the QR Code matrix into a list of lists which use boolean values for the modules (True = dark module, False = light module):

>>> import segno
>>> qr = segno.make('The Beatles')
>>> width, height = qr.symbol_size(scale=2)
>>> res = []
>>> # Scaling factor 2, default border
>>> for row in qr.matrix_iter(scale=2):
>>>     res.append([col == 0x1 for col in row])
>>> width == len(res[0])
True
>>> height == len(res)
True
Parameters:
  • scale (int) – The scaling factor (default: 1).
  • border (int) – The size of border / quiet zone or None to indicate the default border.
  • verbose (bool) – Indicates if the type of the module should be returned instead of 0x1 and 0x0 values. See segno.moduletypes for the return values. This feature is currently in EXPERIMENTAL state.
Raises:

ValueError if the scaling factor or the border is invalid (i.e. negative).

show(delete_after=20, scale=10, border=None, color=u'#000', background=u'#fff')

Displays this QR code.

This method is mainly intended for debugging purposes.

This method saves QR code as an image (by default with a scaling factor of 10) to a temporary file and opens it with the standard PNG viewer application or within the standard webbrowser. The temporary file is deleted afterwards (unless delete_after is set to None).

If this method does not show any result, try to increase the delete_after value or set it to None

Parameters:
  • delete_after (int or None) – Time in seconds to wait till the temporary file is deleted.
  • scale (int) – Integer indicating the size of a single module.
  • border (int or None) – Integer indicating the size of the quiet zone. If set to None (default), the recommended border size will be used.
  • color – The color of the dark modules (default: black).
  • background – The color of the background (default: white).
svg_data_uri(xmldecl=False, encode_minimal=False, omit_charset=False, nl=False, **kw)

Converts the QR Code into a SVG data URI.

The XML declaration is omitted by default (set xmldecl to True to enable it), further the newline is omitted by default (set nl to True to enable it).

Aside from the missing out parameter, the different xmldecl and nl default values, and the additional parameters encode_minimal and omit_charset, this method uses the same parameters as the usual SVG serializer, see save() and the available SVG parameters

Parameters:
  • xmldecl (bool) – Indicates if the XML declaration should be serialized (default: False)
  • encode_minimal (bool) – Indicates if the resulting data URI should use minimal percent encoding (disabled by default).
  • omit_charset (bool) – Indicates if the ;charset=... should be omitted (disabled by default)
Return type:

str

png_data_uri(**kw)

Converts the QR Code into a PNG data URI.

Uses the same keyword parameters as the usual PNG serializer, see save() and the available PNG parameters

Return type:str
terminal(out=None, border=None)

Serializes the matrix as ANSI escape code.

Under Windows, no ANSI escape sequence is generated but the Windows API is used unless out is a writable object or using WinAPI fails.

Parameters:
  • out – Filename or a file-like object supporting to write text. If None (default), the matrix is written to sys.stdout.
  • border (int) – Integer indicating the size of the quiet zone. If set to None (default), the recommended border size will be used (4 for QR Codes, 2 for Micro QR Codes).
save(out, kind=None, **kw)

Serializes the QR Code in one of the supported formats. The serialization format depends on the filename extension.

Common keywords

Name Description
scale Integer or float indicating the size of a single module. Default: 1. The interpretation of the scaling factor depends on the serializer. For pixel-based output (like PNG) the scaling factor is interepreted as pixel-size (1 = 1 pixel). EPS interprets 1 as 1 point (1/72 inch) per module. Some serializers (like SVG) accept float values. If the serializer does not accept float values, the value will be converted to an integer value (note: int(1.6) == 1).
border Integer indicating the size of the quiet zone. If set to None (default), the recommended border size will be used (4 for QR Codes, 2 for a Micro QR Codes). A value of 0 indicates that border should be omitted.
color A string or tuple representing a color value for the dark modules. The default value is “black”. The color can be provided as (R, G, B) tuple, as web color name (like “red”) or in hexadecimal format (#RGB or #RRGGBB). Some serializers (i.e. SVG and PNG) accept an alpha transparency value like #RRGGBBAA.
background A string or tuple representing a color for the light modules or background. See color for valid values. The default value depends on the serializer. SVG uses no background color (None) by default, other serializers, like PNG, use “white” as default background color.

Scalable Vector Graphics (SVG)

Name Description
out Filename or io.BytesIO
kind “svg” or “svgz” (to create a gzip compressed SVG)
scale integer or float
color Default: “#000” (black) None is a valid value. If set to None, the resulting path won’t have a “stroke” attribute. The “stroke” attribute may be defined via CSS (external). If an alpha channel is defined, the output depends of the used SVG version. For SVG versions >= 2.0, the “stroke” attribute will have a value like “rgba(R, G, B, A)”, otherwise the path gets another attribute “stroke-opacity” to emulate the alpha channel. To minimize the document size, the SVG serializer uses automatically the shortest color representation: If a value like “#000000” is provided, the resulting document will have a color value of “#000”. If the color is “#FF0000”, the resulting color is not “#F00”, but the web color name “red”.
background Default value None. If this paramater is set to another value, the resulting image will have another path which is used to define the background color. If an alpha channel is used, the resulting path may have a “fill-opacity” attribute (for SVG version < 2.0) or the “fill” attribute has a “rgba(R, G, B, A)” value. See keyword “color” for further details.
xmldecl Boolean value (default: True) indicating whether the document should have an XML declaration header. Set to False to omit the header.
svgns Boolean value (default: True) indicating whether the document should have an explicit SVG namespace declaration. Set to False to omit the namespace declaration. The latter might be useful if the document should be embedded into a HTML 5 document where the SVG namespace is implicitly defined.
title String (default: None) Optional title of the generated SVG document.
desc String (default: None) Optional description of the generated SVG document.
svgid A string indicating the ID of the SVG document (if set to None (default), the SVG element won’t have an ID).
svgclass Default: “segno”. The CSS class of the SVG document (if set to None, the SVG element won’t have a class).
lineclass Default: “qrline”. The CSS class of the path element (which draws the dark modules (if set to None, the path won’t have a class).
omitsize Indicates if width and height attributes should be omitted (default: False). If these attributes are omitted, a viewBox attribute will be added to the document.
unit Default: None Inidctaes the unit for width / height and other coordinates. By default, the unit is unspecified and all values are in the user space. Valid values: em, ex, px, pt, pc, cm, mm, in, and percentages (any string is accepted, this parameter is not validated by the serializer)
encoding Encoding of the XML document. “utf-8” by default.
svgversion SVG version (default: None). If specified (a float), the resulting document has an explicit “version” attribute. If set to None, the document won’t have a “version” attribute. This parameter is not validated.
compresslevel Default: 9. This parameter is only valid, if a compressed SVG document should be created (file extension “svgz”). 1 is fastest and produces the least compression, 9 is slowest and produces the most. 0 is no compression.

Portable Network Graphics (PNG)

This writes either a grayscale (maybe with transparency) PNG (color type 0) or a palette-based (maybe with transparency) image (color type 3). If the color / background values are None, white or black, the serializer chooses the more compact grayscale mode, in all other cases a palette-based image is written.

Name Description
out Filename or io.BytesIO
kind “png”
scale integer
color Default: “#000” (black) None is a valid value iff background is not None. If set to None, the dark modules become transparent.
background Default value “#fff” (white) See keyword “color” for further details.
compresslevel Default: 9. Integer indicating the compression level for the IDAT (data) chunk. 1 is fastest and produces the least compression, 9 is slowest and produces the most. 0 is no compression.
dpi Default: None. Specifies the DPI value for the image. By default, the DPI value is unspecified. Please note that the DPI value is converted into meters (maybe with rounding errors) since PNG does not support the unit “dots per inch”.
colormap Optional module type -> color mapping. If provided, the “color” and “background” arguments are ignored. All undefined module types will have the default colors (light: white, dark: black). See “”color” for valid color values. None is accepted as valid color value as well (becomes transparent).

Encapsulated PostScript (EPS)

Name Description
out Filename or io.StringIO
kind “eps”
scale integer or float
color Default: “#000” (black)
background Default value: None (no background)

Portable Document Format (PDF)

Name Description
out Filename or io.BytesIO
kind “pdf”
scale integer or float
color Default: “#000” (black)
background Default value: None (no background)
compresslevel Default: 9. Integer indicating the compression level. 1 is fastest and produces the least compression, 9 is slowest and produces the most. 0 is no compression.

Text (TXT)

Does not support the “scale” keyword!

Name Description
out Filename or io.StringIO
kind “txt”
color Default: “1”
background Default: “0”

ANSI escape code

Supports the “border” keyword, only!

Name Description
out Filename or io.StringIO
kind “ans”

Portable Bitmap (PBM)

Name Description
out Filename or io.BytesIO
kind “pbm”
scale integer
plain Default: False. Boolean to switch between the P4 and P1 format. If set to True, the (outdated) P1 serialization format is used.

Portable Arbitrary Map (PAM)

Name Description
out Filename or io.BytesIO
kind “pam”
scale integer
color Default: “#000” (black).
background Default value “#fff” (white). Use None for a transparent background.

LaTeX / PGF/TikZ

To use the output of this serializer, the PGF/TikZ (and optionally hyperref) package is required in the LaTeX environment. The serializer itself does not depend on any external packages.

Name Description
out Filename or io.StringIO
kind “tex”
scale integer or float
color LaTeX color name (default: “black”). The color is written “at it is”, please ensure that the color is a standard color or it has been defined in the enclosing LaTeX document.
url Default: None. Optional URL where the QR Code should point to. Requires the hyperref package in your LaTeX environment.

X BitMap (XBM)

Name Description
out Filename or io.StringIO
kind “xbm”
scale integer
name Name of the variable (default: “img”)

X PixMap (XPM)

Name Description
out Filename or io.StringIO
kind “xpm”
scale integer
color Default: “#000” (black).
background Default value “#fff” (white) None indicates a transparent background.
name Name of the variable (default: “img”)
Parameters:
  • out – A filename or a writable file-like object with a name attribute. Use the kind parameter if out is a io.BytesIO or io.StringIO stream which don’t have a name attribute.
  • kind – If the desired output format cannot be determined from the out parameter, this parameter can be used to indicate the serialization format (i.e. “svg” to enforce SVG output)
  • kw – Any of the supported keywords by the specific serialization method.
class segno.QRCodeSequence

Represents a sequence of 1 .. n (max. n = 16) QRCode instances.

Iff this sequence contains only one item, it behaves like QRCode.

terminal(out=None, border=None)

Serializes the sequence of QR Codes as ANSI escape code.

See QRCode.terminal() for details.

save(out, kind=None, **kw)

Saves the sequence of QR Code to out.

If out is a filename, this method modifies the filename and adds <Number of QR Codes>-<Current QR Code> to it. structured-append.svg becomes (if the sequence contains two QR Codes): structured-append-02-01.svg and structured-append-02-02.svg

Please note that using a file or file-like object may result into an invalid serialization format since all QR Codes are written to the same output.

See QRCode.save() for a detailed enumeration of options.

exception segno.QRCodeError

Generic QR Code error.

exception segno.ErrorLevelError

Indicates errors related to QR Code error correction level.

exception segno.ModeError

Indicates errors related to QR Code mode.

exception segno.MaskError

Indicates errors related to QR Code data mask.

exception segno.VersionError

Indicates errors related to the QR Code version.

exception segno.DataOverflowError

Indicates a problem that the provided data does not fit into the provided QR Code version or the data is too large in general.

Utilities

Utility functions useful for writers or QR Code objects.

segno.utils.get_default_border_size(version)

Returns the default border size (quiet zone) for the provided version.

Parameters:version (int) – 1 .. 40 or a Micro QR Code version constant.
Return type:int
segno.utils.get_border(version, border)

Returns border if not None, otherwise the default border size for the provided QR Code.

Parameters:
  • version (int) – 1 .. 40 or a Micro QR Code version constant
  • border (int or None) – The size of the quiet zone or None.
Return type:

int

segno.utils.get_symbol_size(version, scale=1, border=None)

Returns the symbol size (width x height) with the provided border and scaling factor.

Parameters:
  • version (int) – A version constant.
  • scale (int or float) – Indicates the size of a single module (default: 1). The size of a module depends on the used output format; i.e. in a PNG context, a scaling factor of 2 indicates that a module has a size of 2 x 2 pixel. Some outputs (i.e. SVG) accept floating point values.
  • border (int) – The border size or None to specify the default quiet zone (4 for QR Codes, 2 for Micro QR Codes).
Return type:

tuple (width, height)

segno.utils.check_valid_scale(scale)

Raises a ValueError iff scale is negative or zero.

Parameters:scale (float or int) – Scaling factor.
segno.utils.check_valid_border(border)

Raises a ValueError iff border is negative.

Parameters:border (int) – Indicating the size of the quiet zone.
segno.utils.matrix_to_lines(matrix, x, y, incby=1)

Converts the matrix into an iterable of ((x1, y1), (x2, y2)) tuples which represent a sequence (horizontal line) of dark modules.

The path starts at the 1st row of the matrix and moves down to the last row.

Parameters:
  • matrix – An iterable of bytearrays.
  • x – Initial position on the x-axis.
  • y – Initial position on the y-axis.
  • incby – Value to move along the y-axis (default: 1).
Return type:

iterable of (x1, y1), (x2, y2) tuples

segno.utils.matrix_iter(matrix, version, scale=1, border=None)

Returns an iterator / generator over the provided matrix which includes the border and the scaling factor.

If either the scale or border value is invalid, a ValueError is raised.

Parameters:
  • matrix – An iterable of bytearrays.
  • version (int) – A version constant.
  • scale (int) – The scaling factor (default: 1).
  • border (int) – The border size or None to specify the default quiet zone (4 for QR Codes, 2 for Micro QR Codes).
Raises:

ValueError if an illegal scale or border value is provided

segno.utils.matrix_iter_verbose(matrix, version, scale=1, border=None)

EXPERIMENTAL: Returns an iterator / generator over the provided matrix which includes the border and the scaling factor.

This iterator / generator returns different values for dark / light modules and therefor the different parts (like the finder patterns, alignment patterns etc.) are distinguishable. If this information isn’t necessary, use the matrix_iter() function because it is much cheaper and faster.

If either the scale or border value is invalid, a py:exc:ValueError is raised.

Parameters:
  • matrix – An iterable of bytearrays.
  • version (int) – A version constant.
  • scale (int) – The scaling factor (default: 1).
  • border (int) – The border size or None to specify the default quiet zone (4 for QR Codes, 2 for Micro QR Codes).
Raises:

ValueError if an illegal scale or border value is provided

Module Types

Module types (EXPERIMENTAL).

To distinguish between dark and light modules without taking the concrete value into account, use:

if m >> 8:
    print('dark module')

if not m >> 8:
    print('light module')
segno.moduletypes.TYPE_ALIGNMENT_PATTERN_DARK = 2560

Dark alignment pattern module.

segno.moduletypes.TYPE_ALIGNMENT_PATTERN_LIGHT = 10

Light alignment pattern module.

segno.moduletypes.TYPE_DARKMODULE = 512

A single dark module which occurs in QR Codes (but not in Micro QR Codes).

segno.moduletypes.TYPE_DATA_DARK = 1024

Dark module in the encoding area (either a data module or an error correction module).

segno.moduletypes.TYPE_DATA_LIGHT = 4

Light module in the encoding area (either a data module or an error correction module).

segno.moduletypes.TYPE_FINDER_PATTERN_DARK = 1536

Dark finder module.

segno.moduletypes.TYPE_FINDER_PATTERN_LIGHT = 6

Light finder module

segno.moduletypes.TYPE_FORMAT_DARK = 3584

Dark format information module.

segno.moduletypes.TYPE_FORMAT_LIGHT = 14

Light format information module.

segno.moduletypes.TYPE_QUIET_ZONE = 18

Border of light modules.

segno.moduletypes.TYPE_SEPARATOR = 8

Separator around the finder patterns (light module)

segno.moduletypes.TYPE_TIMING_DARK = 3072

Dark timing patten module.

segno.moduletypes.TYPE_TIMING_LIGHT = 12

Light timing pattern module.

segno.moduletypes.TYPE_VERSION_DARK = 4096

Dark version information module.

segno.moduletypes.TYPE_VERSION_LIGHT = 16

Light version information module.

High level QR Code factories

Additional factory functions for common QR Codes.

The factory functions which return a QR Code with the minimum error correction level “L” (or better). To create a (Micro) QR Code which should use a specific error correction level or version etc., use the “_data” factory functions which return a string which can be used as input for segno.make().

segno.helpers.make_email(to, cc=None, bcc=None, subject=None, body=None)

Encodes either a simple e-mail address or a complete message with (blind) carbon copies and a subject and a body.

Parameters:
  • to (str or iterable of strings) – The email address (recipient). Multiple values are allowed.
  • cc (str, iterable of strings, or None) – The carbon copy recipient. Multiple values are allowed.
  • bcc (str, iterable of strings, or None) – The blind carbon copy recipient. Multiple values are allowed.
  • subject (str or None) – The subject.
  • body (str or None) – The message body.
Return type:

segno.QRCode

segno.helpers.make_epc_qr(name, iban, amount, text=None, reference=None, bic=None, purpose=None, encoding=None)

Creates and returns an European Payments Council Quick Response Code (EPC QR Code) version 002.

Note

Either the text or reference must be provided but not both

Note

Neither the IBAN, BIC, nor remittance reference number or any other information is validated (aside from checks regarding the allowed string lengths).

Parameters:
  • name (str) – Name of the recipient.
  • iban (str) – International Bank Account Number (IBAN)
  • amount (int, float, decimal.Decimal) – The amount (in EUR) to transfer. The currency is always Euro, no other currencies are supported.
  • text (str) – Remittance Information (unstructured)
  • reference (str) – Remittance Information (structured)
  • bic (str) – Bank Identifier Code (BIC). Optional, only required for non-EEA countries.
  • purpose (str) – SEPA purpose code.
  • encoding (int) – By default, this function tries to find the best, minimal encoding. If another encoding should be used, the number of the encoding can be provided: 1: UTF-8, 2: ISO 8859-1, 3: ISO 8859-2, 4: ISO 8859-4, 5: ISO 8859-5, 6: ISO 8859-7, 7: ISO 8859-10, 8: ISO 8859-15
Return type:

segno.QRCode

segno.helpers.make_geo(lat, lng)

Returns a QR Code which encodes geographic location using the geo URI scheme.

Parameters:
Return type:

segno.QRCode

segno.helpers.make_geo_data(lat, lng)

Creates a geo location URI.

Parameters:
Return type:

str

segno.helpers.make_make_email_data(to, cc=None, bcc=None, subject=None, body=None)

Creates either a simple “mailto:” URL or complete e-mail message with (blind) carbon copies and a subject and a body.

Parameters:
  • to (str or iterable of strings) – The email address (recipient). Multiple values are allowed.
  • cc (str, iterable of strings, or None) – The carbon copy recipient. Multiple values are allowed.
  • bcc (str, iterable of strings, or None) – The blind carbon copy recipient. Multiple values are allowed.
  • subject (str or None) – The subject.
  • body (str or None) – The message body.
Return type:

str

segno.helpers.make_mecard(name, reading=None, email=None, phone=None, videophone=None, memo=None, nickname=None, birthday=None, url=None, pobox=None, roomno=None, houseno=None, city=None, prefecture=None, zipcode=None, country=None)

Returns a QR Code which encodes a MeCard

Parameters:
  • name (str) – Name. If it contains a comma, the first part is treated as lastname and the second part is treated as forename.
  • reading (str or None) – Designates a text string to be set as the kana name in the phonebook
  • email (str, iterable of strings, or None) – E-mail address. Multiple values are allowed.
  • phone (str, iterable of strings, or None) – Phone number. Multiple values are allowed.
  • videophone (str, iterable of strings, or None) – Phone number for video calls. Multiple values are allowed.
  • memo (str or None) – A notice for the contact.
  • nickname (str or None) – Nickname.
  • birthday (str, datetime.date or None) – Birthday. If a string is provided, it should encode the date as YYYYMMDD value.
  • url (str, iterable of strings, or None) – Homepage. Multiple values are allowed.
  • pobox (str or None) – P.O. box (address information).
  • roomno (str or None) – Room number (address information).
  • houseno (str or None) – House number (address information).
  • city (str or None) – City (address information).
  • prefecture (str or None) – Prefecture (address information).
  • zipcode (str or None) – Zip code (address information).
  • country (str or None) – Country (address information).
Return type:

segno.QRCode

segno.helpers.make_mecard_data(name, reading=None, email=None, phone=None, videophone=None, memo=None, nickname=None, birthday=None, url=None, pobox=None, roomno=None, houseno=None, city=None, prefecture=None, zipcode=None, country=None)

Creates a string encoding the contact information as MeCard.

Parameters:
  • name (str) – Name. If it contains a comma, the first part is treated as lastname and the second part is treated as forename.
  • reading (str or None) – Designates a text string to be set as the kana name in the phonebook
  • email (str, iterable of strings, or None) – E-mail address. Multiple values are allowed.
  • phone (str, iterable of strings, or None) – Phone number. Multiple values are allowed.
  • videophone (str, iterable of strings, or None) – Phone number for video calls. Multiple values are allowed.
  • memo (str or None) – A notice for the contact.
  • nickname (str or None) – Nickname.
  • birthday (str, datetime.date or None) – Birthday. If a string is provided, it should encode the date as YYYYMMDD value.
  • url (str, iterable of strings, or None) – Homepage. Multiple values are allowed.
  • pobox (str or None) – P.O. box (address information).
  • roomno (str or None) – Room number (address information).
  • houseno (str or None) – House number (address information).
  • city (str or None) – City (address information).
  • prefecture (str or None) – Prefecture (address information).
  • zipcode (str or None) – Zip code (address information).
  • country (str or None) – Country (address information).
Return type:

str

segno.helpers.make_vcard(name, displayname, email=None, phone=None, fax=None, videophone=None, memo=None, nickname=None, birthday=None, url=None, pobox=None, street=None, city=None, region=None, zipcode=None, country=None, org=None, lat=None, lng=None, source=None, rev=None, title=None, photo_uri=None)

Creates a QR Code which encodes a vCard version 3.0.

Only a subset of available vCard 3.0 properties <https://tools.ietf.org/html/rfc2426> is supported.

Parameters:
  • name (str) – The name. If it contains a semicolon, , the first part is treated as lastname and the second part is treated as forename.
  • displayname (str) – Common name.
  • email (str, iterable of strings, or None) – E-mail address. Multiple values are allowed.
  • phone (str, iterable of strings, or None) – Phone number. Multiple values are allowed.
  • fax (str, iterable of strings, or None) – Fax number. Multiple values are allowed.
  • videophone (str, iterable of strings, or None) – Phone number for video calls. Multiple values are allowed.
  • memo (str or None) – A notice for the contact.
  • nickname (str or None) – Nickname.
  • birthday (str, datetime.date or None) – Birthday. If a string is provided, it should encode the date as YYYY-MM-DD value.
  • url (str, iterable of strings, or None) – Homepage. Multiple values are allowed.
  • pobox (str or None) – P.O. box (address information).
  • street (str or None) – Street address.
  • city (str or None) – City (address information).
  • region (str or None) – Region (address information).
  • zipcode (str or None) – Zip code (address information).
  • country (str or None) – Country (address information).
  • org (str or None) – Company / organization name.
  • lat (float or None) – Latitude.
  • lng (float or None) – Longitude.
  • source (str or None) – URL where to obtain the vCard.
  • rev (str, datetime.date or None) – Revision of the vCard / last modification date.
  • title (str, iterable of strings, or None) – Job Title. Multiple values are allowed.
  • photo_uri (str, iterable of strings, or None) – Photo URI. Multiple values are allowed.
Return type:

segno.QRCode

segno.helpers.make_vcard_data(name, displayname, email=None, phone=None, fax=None, videophone=None, memo=None, nickname=None, birthday=None, url=None, pobox=None, street=None, city=None, region=None, zipcode=None, country=None, org=None, lat=None, lng=None, source=None, rev=None, title=None, photo_uri=None)

Creates a string encoding the contact information as vCard 3.0.

Only a subset of available vCard 3.0 properties <https://tools.ietf.org/html/rfc2426> is supported.

Parameters:
  • name (str) – The name. If it contains a semicolon, , the first part is treated as lastname and the second part is treated as forename.
  • displayname (str) – Common name.
  • email (str, iterable of strings, or None) – E-mail address. Multiple values are allowed.
  • phone (str, iterable of strings, or None) – Phone number. Multiple values are allowed.
  • fax (str, iterable of strings, or None) – Fax number. Multiple values are allowed.
  • videophone (str, iterable of strings, or None) – Phone number for video calls. Multiple values are allowed.
  • memo (str or None) – A notice for the contact.
  • nickname (str or None) – Nickname.
  • birthday (str, datetime.date or None) – Birthday. If a string is provided, it should encode the date as YYYY-MM-DD value.
  • url (str, iterable of strings, or None) – Homepage. Multiple values are allowed.
  • pobox (str or None) – P.O. box (address information).
  • street (str or None) – Street address.
  • city (str or None) – City (address information).
  • region (str or None) – Region (address information).
  • zipcode (str or None) – Zip code (address information).
  • country (str or None) – Country (address information).
  • org (str or None) – Company / organization name.
  • lat (float or None) – Latitude.
  • lng (float or None) – Longitude.
  • source (str or None) – URL where to obtain the vCard.
  • rev (str, datetime.date or None) – Revision of the vCard / last modification date.
  • title (str, iterable of strings, or None) – Job Title. Multiple values are allowed.
  • photo_uri (str, iterable of strings, or None) – Photo URI. Multiple values are allowed.
Return type:

str

segno.helpers.make_wifi(ssid, password, security, hidden=False)

Creates a WIFI configuration QR Code.

Parameters:
  • ssid (str) – The SSID of the network.
  • password (str or None) – The password.
  • security (str or None) – Authentication type; the value should be “WEP” or “WPA”. Set to None to omit the value. “nopass” is equivalent to setting the value to None but in the former case, the value is not omitted.
  • hidden (bool) – Indicates if the network is hidden (default: False)
Return type:

segno.QRCode

segno.helpers.make_wifi_data(ssid, password, security, hidden=False)

Creates WIFI configuration string.

Parameters:
  • ssid (str) – The SSID of the network.
  • password (str or None) – The password.
  • security (str or None) – Authentication type; the value should be “WEP” or “WPA”. Set to None to omit the value. “nopass” is equivalent to setting the value to None but in the former case, the value is not omitted.
  • hidden (bool) – Indicates if the network is hidden (default: False)
Return type:

str