API

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”, “kanji” or “hanzi”. If the value is None (default) the appropriate mode will automatically be determined. If version refers to a Micro QR code, this function may raise a ValueError if the provided mode is not supported.

    The mode parameter is case insensitive.

    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

    hanzi

    1 - 40

    Note

    The Hanzi mode may not be supported by all QR code readers since it is not part of ISO/IEC 18004:2015(E). For this reason, this mode must be specified explicitly by the user:

    import segno
    qrcode = segno.make('书读百遍其义自现', mode='hanzi')
    

  • 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 ValueError 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

ValueError or DataOverflowError: In case the data does not fit into a (Micro) QR Code or it does not fit into the provided version.

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

Returns the matrix.

Return type

tuple of bytearray instances.

mask

Returns the data mask pattern reference

Return type

int

property 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

property 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

property mode

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

Return type

str or None

property 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

property 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

property 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
>>> qrcode = segno.make('The Beatles')
>>> width, height = qrcode.symbol_size(scale=2)
>>> res = []
>>> # Scaling factor 2, default border
>>> for row in qrcode.matrix_iter(scale=2):
>>>     res.append([col == 0x1 for col in row])
>>> width == len(res[0])
True
>>> height == len(res)
True

If verbose is True, the iterator returns integer constants which indicate the type of the module, i.e. segno.consts.TYPE_FINDER_PATTERN_DARK, segno.consts.TYPE_FINDER_PATTERN_LIGHT, segno.consts.TYPE_QUIET_ZONE etc.

To check if the returned module type is dark or light, use:

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

if not mt >> 8:
    print('light module')
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.consts 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, dark='#000', light='#fff')

Displays this QR code.

This method is mainly intended for debugging purposes.

This method saves the 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.

  • dark – The color of the dark modules (default: black).

  • light – The color of the light modules (default: white).

svg_data_uri(xmldecl=False, encode_minimal=False, omit_charset=False, nl=False, **kw)

Converts the QR code into an 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

Note

In order to embed a SVG image in HTML without generating a file, the svg_inline() method could serve better results, as it usually produces a smaller output.

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)

  • nl (bool) – Indicates if the document should have a trailing newline (default: False)

Return type

str

svg_inline(**kw)

Returns an SVG representation which is embeddable into HTML5 contexts.

Due to the fact that HTML5 directly supports SVG, various elements of an SVG document can or should be suppressed (i.e. the XML declaration and the SVG namespace).

This method returns a string that can be used in an HTML context.

This method uses the same parameters as the usual SVG serializer, see save() and the available SVG parameters (the out and kind parameters are not supported).

The returned string can be used directly in Jinja and Django templates, provided the safe filter is used which marks a string as not requiring further HTML escaping prior to output.

<div>{{ qr.svg_inline(dark='#228b22', scale=3) | safe }}</div>
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, compact=False)

Serializes the matrix as ANSI escape code or Unicode Block Elements (if compact is True).

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

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).

  • compact (bool) – Indicates if a more compact QR code should be shown (default: False).

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 interpreted 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.

dark

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.

light

A string or tuple representing a color for the light modules. See dark for valid values. The default value depends on the serializer. SVG uses no color (None) for light modules by default, other serializers, like PNG, use “white” as default light color.

Module Colors

Name

Description

finder_dark

Color of the dark modules of the finder patterns Default: undefined, use value of “dark”

finder_light

Color of the light modules of the finder patterns Default: undefined, use value of “light”

data_dark

Color of the dark data modules Default: undefined, use value of “dark”

data_light

Color of the light data modules. Default: undefined, use value of “light”.

version_dark

Color of the dark modules of the version information. Default: undefined, use value of “dark”.

version_light

Color of the light modules of the version information, Default: undefined, use value of “light”.

format_dark

Color of the dark modules of the format information. Default: undefined, use value of “dark”.

format_light

Color of the light modules of the format information. Default: undefined, use value of “light”.

alignment_dark

Color of the dark modules of the alignment patterns. Default: undefined, use value of “dark”.

alignment_light

Color of the light modules of the alignment patterns. Default: undefined, use value of “light”.

timing_dark

Color of the dark modules of the timing patterns. Default: undefined, use value of “dark”.

timing_light

Color of the light modules of the timing patterns. Default: undefined, use value of “light”.

separator

Color of the separator. Default: undefined, use value of “light”.

dark_module

Color of the dark module (a single dark module which occurs in all QR Codes but not in Micro QR Codes. Default: undefined, use value of “dark”.

quiet_zone

Color of the quiet zone / border. Default: undefined, use value of “light”.

Scalable Vector Graphics (SVG)

All common keywords and module colors are supported.

Name

Description

out

Filename or io.BytesIO

kind

“svg” or “svgz” (to create a gzip compressed SVG)

scale

integer or float

dark

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”.

light

Default value None. If this parameter is set to another value, the resulting image will have another path which is used to define the color of the light modules. 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.

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 Indicates 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.

draw_transparent

Indicates if transparent SVG paths should be added to the graphic (default: False)

nl

Indicates if the document should have a trailing newline (default: True)

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 dark / light values are None, white or black, the serializer chooses the more compact grayscale mode, in all other cases a palette-based image is written.

All common keywords and module colors are supported.

Name

Description

out

Filename or io.BytesIO

kind

“png”

scale

integer

dark

Default: “#000” (black) None is a valid value iff light is not None. If set to None, the dark modules become transparent.

light

Default value “#fff” (white) See keyword “dark” 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”.

Encapsulated PostScript (EPS)

All common keywords are supported.

Name

Description

out

Filename or io.StringIO

kind

“eps”

scale

integer or float

dark

Default: “#000” (black)

light

Default value: None (transparent light modules)

Portable Document Format (PDF)

All common keywords are supported.

Name

Description

out

Filename or io.BytesIO

kind

“pdf”

scale

integer or float

dark

Default: “#000” (black)

light

Default value: None (transparent light modules)

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)

Aside of “scale”, all common keywords are supported.

Name

Description

out

Filename or io.StringIO

kind

“txt”

dark

Default: “1”

light

Default: “0”

ANSI escape code

Supports the “border” keyword, only!

Name

Description

out

Filename or io.StringIO

kind

“ans”

Portable Bitmap (PBM)

All common keywords are supported.

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)

All common keywords are supported.

Name

Description

out

Filename or io.BytesIO

kind

“pam”

scale

integer

dark

Default: “#000” (black).

light

Default value “#fff” (white). Use None for transparent light modules.

Portable Pixmap (PPM)

All common keywords and module colors are supported.

Name

Description

out

Filename or io.BytesIO

kind

“ppm”

scale

integer

dark

Default: “#000” (black).

light

Default value “#fff” (white).

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.

All common keywords are supported.

Name

Description

out

Filename or io.StringIO

kind

“tex”

scale

integer or float

dark

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 the LaTeX environment.

X BitMap (XBM)

All common keywords are supported.

Name

Description

out

Filename or io.StringIO

kind

“xbm”

scale

integer

name

Name of the variable (default: “img”)

X PixMap (XPM)

All common keywords are supported.

Name

Description

out

Filename or io.StringIO

kind

“xpm”

scale

integer

dark

Default: “#000” (black). None indicates transparent dark modules.

light

Default value “#fff” (white) None indicates transparent light modules.

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 (str) – Default None. 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). The value is case insensitive.

  • kw – Any of the supported keywords by the specific serializer.

class segno.QRCodeSequence(qrcodes)

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, compact=False)

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 codes 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.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.

This exception is inherited from ValueError and is only raised if the data does not fit into the provided (Micro) QR Code version.

Basically it is sufficient to catch a ValueError.

High level QR Code factories

Additional factory functions for common QR codes.

Aside from make_epc_qr(), the factory functions 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.

The returned segno.QRCode uses always the error correction level “M” and utilizes max. version 13 to fulfill the constraints of the EPC QR Code standard.

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 (str or int) –

    By default, this function tries to find the best, minimal encoding. If another encoding should be used, the encoding name or the encoding constant (an integer) 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”

    The encoding is case-insensitive.

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=None, security=None, 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=None, security=None, 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