Python libremarkable#

class libremarkable.Keymap#

alias of dict [ tuple [ str | None, str | None ]]

libremarkable.deviceType: DeviceType#

Current device type

libremarkable.DEFAULT_FONT_SIZE = 24: int#

The default font size

libremarkable.DEFAULT_KEYMAP: Keymap#

The default keymap

libremarkable.Framebuffer: libremarkable._framebuffer.FrameBuffer#

Framebuffer API instance

class libremarkable._framebuffer.FrameBuffer#

Bases: object

Framebuffer

classmethod __contains__(color)#

Check to see if a colour is present in the framebuffer memory

Parameters:

color (c_ushort | str | int) – colour value or name of colour

Return type:

bool

Returns:

if the framebuffer contains the colour

classmethod __getitem__(key)#

Get data from the framebuffer memory

Parameters:

key (int | slice | tuple[int, int]) – byte offset, slice, or coordinate

Return type:

c_ushort | list[c_ushort]

Returns:

colour value or list of colour values

__init__()#
classmethod __iter__()#

Iterate through the framebuffer memory

Return type:

iter

classmethod __len__()#

Get the size of the framebuffer memory

Return type:

int

classmethod __setitem__(key, value)#

Set framebuffer memory

Parameters:
Return type:

None

classmethod draw_image(left, top, image)#

Draw an image into the framebufffer memory

Parameters:
  • left (int) – x coordinate

  • top (int) – y coordinate

  • image (<module ‘PIL.Image’ from ‘/home/runner/work/python-libremarkable/python-libremarkable/.venv/lib/python3.11/site-packages/PIL/Image.py’>) – Image to draw

Return type:

None

classmethod draw_line(x1, y1, x2, y2, color)#

Draw a line between two points in the framebuffer memory

Parameters:
  • x1 (int) – starting x coordinate

  • y1 (int) – starting y coordinate

  • x2 (int) – ending x coordinate

  • y2 (int) – ending y coordinate

  • color (c_ushort | str) – colour value or name of colour

Return type:

None

classmethod draw_multiline_text(left, top, width, height, text, color='black', fontSize=24, align='left')#

Draw multiline text on the framebuffer memory

Parameters:
  • left (int) – left coordinate

  • top (int) – right coordinate

  • width (int) – width of area to draw text to

  • height (int) – height of area to draw text to

  • text (str) – text to draw

  • color (c_ushort | str) – color value or name of color to use

  • fontSize (int) – Size of font to use

  • align (str) – text align

classmethod draw_rect(left, top, right, bottom, color, lineSize=1)#

Draw a rectangle in the framebuffer memory

Parameters:
  • left (int) – top left x coordinate

  • top (int) – top left y coordinate

  • right (int) – bottom right x coordinate

  • bottom (int) – bottom right y coordinate

  • color (c_ushort | str) – colour value or name of colour to use for the lines

  • lineSize (int) – size of lines to draw

Return type:

None

classmethod draw_text(left, top, width, height, text, color='black', fontSize=24)#

Draw text on the framebuffer memory

Parameters:
  • left (int) – left coordinate

  • top (int) – right coordinate

  • width (int) – width of area to draw text to

  • height (int) – height of area to draw text to

  • text (str) – text to draw

  • color (c_ushort | str) – color value or name of color to use

  • fontSize (int) – Size of font to use

classmethod get_offset(x, y)#

Get the offset of a x,y on the framebuffer

Parameters:
  • x (int) – x coordinate

  • y (int) – y coordinate

Return type:

int

Returns:

byte offset

classmethod get_pixel(x, y)#

Get the value for a pixel in the framebuffer memory

Parameters:
  • x (int) – x coordinate

  • y (int) – y coordinate

Return type:

int

Returns:

pixel value

classmethod get_row(x, y, width)#

Get the data for a row in the framebuffer memory

Parameters:
  • x (int) – x coordinate

  • y (int) – y coordinate

  • width (int) – width on row to get

Return type:

tuple[int]

Returns:

slice of data from row

classmethod get_row_offset(y)#

Get the offset of a row on the framebuffer

Parameters:

y (int) – y coordinate of the row

Return type:

int

Returns:

byte offset

static getcolor(name_or_hex)#

Get the value for a colour name or hex

Name_or_hex:

colour name of hex

Return type:

c_ushort

Returns:

colour value

static height()#

Get the height of the framebufffer

Return type:

int

classmethod mmap()#

memory map the framebuffer

classmethod open()#

Open the framebuffer

static path()#

Path to framebuffer device

static pixel_size()#

Get the pixel size of the framebufffer in bytes

Return type:

int

static release()#

Release the framebuffer

classmethod set_col(x, y, height, color)#

Set a column in the framebuffer memory to a colour

Parameters:
  • x (int) – x coordinate

  • y (int) – y coordinate

  • height (int) – height of column to set

  • color (c_ushort | str) – colour value or name of colour to use

Return type:

None

classmethod set_color(color)#

Set the framebuffer memory to a colour

Parameters:

color (c_ushort | str) – colour value or name of colour to use

Return type:

None

classmethod set_pixel(x, y, color)#

Set a pixel in the framebuffer memory to a colour

Parameters:
  • x (int) – x coordinate

  • y (int) – y coordinate

Color:

colour value or string name of colour to use

Return type:

None

classmethod set_rect(left, top, width, height, color)#

Set a rectangle in the framebuffer memory to a colour

Parameters:
  • left (int) – x coordinate

  • top (int) – y coordinate

  • width (int) – width of rectangle

  • height (int) – height of rectangle

  • color (c_ushort | str) – colour value or name of colour to use

Return type:

None

classmethod set_row(x, y, width, color)#

Set a row in the framebuffer memory to a colour

Parameters:
  • x (int) – x coordinate

  • y (int) – y coordinate

  • width (int) – width on row to set

  • color (c_ushort | str) – colour value or string name of colour to use

Return type:

None

static size()#

Get the size of the framebuffer in bytes

Return type:

int

classmethod to_image(left=0, top=0, width=None, height=None)#

Get an image of the framebuffer memory

Parameters:
  • left (int) – x coordinate

  • top (int) – y coordinate

  • width (int) – width, defaults to entire width

  • height (int) – height, defaults to entire height

Return type:

Image

classmethod update(x, y, width, height, waveform, marker=None, partial=True, sync=False)#

Update a portion of the screen with the contents of the framebuffer memory

Parameters:
  • x (int) – x coordinate of area to update

  • y (int) – y coordinate of area to update

  • width (int) – width of area to update

  • height (int) – height of area to update

  • waveform (WaveformMode) – Waveform to use for the update

  • marker (int) – Update Marker

  • partial (bool) – Partial or full screen update

  • sync (bool) – Perform update synchronously

Return type:

int

Returns:

Update marker

classmethod update_full(waveform, marker=None, sync=False)#

Update the screen with the contents of the framebuffer memory

Parameters:
  • waveform (WaveformMode) – Waveform to use for the update

  • marker (int) – Update Marker

  • sync (bool) – Perform update synchronously

Return type:

int

Returns:

Update marker

static virtual_height()#

Get the virtual height of the framebufffer

Return type:

int

static virtual_width()#

Get the virtual width of the framebufffer

Return type:

int

static wait(marker)#

Wait for an update to finish

Parameters:

marker (int) – Update marker

Return type:

None

static width()#

Get the width of the framebufffer

Return type:

int

static x_offset()#

Get the x offset of the framebufffer

Return type:

int

static y_offset()#

Get the y offset of the framebufffer

Return type:

int

__weakref__#

list of weak references to the object

class libremarkable.DeviceType(value, names=None, *, module=None, qualname=None, type=None, start=1, boundary=None)#
RM1 = 2#

reMarkable 1

RM2 = 3#

reMarkable 2

RMPP = 4#

reMarkable Paper Pro

UNKNOWN = 1#

Unknown device

class libremarkable.Event(device, state)#

Input event

__init__(device, state)#
__repr__()#

Return repr(self).

__weakref__#

list of weak references to the object

data#

Current event data

device#

Event device

previousData#

Previous event data

rawEvents#

Raw events

class libremarkable.Input#

Input API

classmethod deviceType(device)#

Gets the string representation of the device type for an input device

Return type:

str

Returns:

key, wacom, touch, or unknown

classmethod devices()#

Input devices

Return type:

list[InputDevice]

classmethod events(block=False)#

Listen for input events

Parameters:

block (bool) – If listening should block until events are recieved. If you are not blocking, you will recieve an empty event every 100ms if no event happens

Return type:

Iterator[Event | None]

Returns:

Generator of events

classmethod keyDevices()#

Input devices that support EV_KEY

Return type:

list[InputDevice]

classmethod keyboards()#

Keyboard input devices

Return type:

list[InputDevice]

classmethod physicalKeyboards()#

Physical keyboards

Return type:

list[InputDevice]

classmethod positionDevices()#

Input devices that support EV_ABS

Return type:

list[InputDevice]

classmethod rawEvents(devices=None, block=False)#

Get the raw events for input devices

Parameters:
  • devices (list[InputDevice]) – Optional list of devices to listen to

  • block (bool) – If listening should block until events are recieved. If you are not blocking, you will recieve an empty event every 100ms if no event happens

Return type:

Iterator[tuple[InputDevice | None, list[InputEvent]]]

Returns:

Generator of events

classmethod rawKeyEvents(block=False)#

Get the raw events for key input devices

Parameters:

block (bool) – If listening should block until events are recieved. If you are not blocking, you will recieve an empty event every 100ms if no event happens

Return type:

Iterator[tuple[InputDevice, InputEvent] | tuple[None, None]]

Returns:

Generator of events

classmethod rawPositionEvents(block=False)#

Get the raw events for position input devices

Parameters:

block (bool) – If listening should block until events are recieved. If you are not blocking, you will recieve an empty event every 100ms if no event happens

Return type:

Iterator[tuple[InputDevice, InputEvent] | tuple[None, None]]

Returns:

Generator of events

classmethod rawTouchEvents(block=False)#

Get the raw events for touch input devices

Parameters:

block (bool) – If listening should block until events are recieved. If you are not blocking, you will recieve an empty event every 100ms if no event happens

Return type:

Iterator[tuple[InputDevice, InputEvent] | tuple[None, None]]

Returns:

Generator of events

classmethod rawWacomEvents(block=False)#

Get the raw events for tablet input devices

Parameters:

block (bool) – If listening should block until events are recieved. If you are not blocking, you will recieve an empty event every 100ms if no event happens

Return type:

Iterator[tuple[InputDevice, InputEvent] | tuple[None, None]]

Returns:

Generator of events

classmethod touchDevices()#

Input devices that support multitouch

Return type:

list[InputDevice]

classmethod virtualKeyboards()#

Keyboards that are vitual

Return type:

list[InputDevice]

classmethod wacomDevices()#

Input devices that use a stylus

Return type:

list[InputDevice]

__weakref__#

list of weak references to the object

class libremarkable.KeyEvent(device, state)#
__init__(device, state)#
__repr__()#

Return repr(self).

property is_press: bool#

If this was a press event

property is_release: bool#

If this was a release event

property is_repeat: bool#

If this is a repeat event

property is_shift: bool#

If shift is pressed

property keycode: int | None#

keycode that was modified this event

property pressed: set[int]#

Keys that were pressed

property released: set[int]#

Keys that were released

property text: str | None#

Text representation of key pressed

class libremarkable.Orientation(value, names=None, *, module=None, qualname=None, type=None, start=1, boundary=None)#
LANDSCAPE = 3#

Landscape

PORTRAIT = 2#

Portrait

UNKNOWN = 1#

Unknown orientation

class libremarkable.TouchEvent(device, state)#

Touch Event

__init__(device, state)#
__repr__()#

Return repr(self).

property pressure: float | None#

Touch pressure

property previousPressure: float | None#

Previous touch pressure

property previousScreenPos: tuple[int, int] | None#

Previous screen coordinates

property previousTrackingId: int | None#

Previous tracking ID

property previousX: float | None#

Previous x coordinate

property previousY: float | None#

Previous y coordinate

property screenPos: tuple[int, int] | None#

Screen coordinates

property slot: int#

Touch slot

property trackingId: int | None#

Tracking ID

property x: float | None#

x coordinate

property y: float | None#

y coordinate

class libremarkable.WacomEvent(device, state)#

Tablet Event

__init__(device, state)#
__repr__()#

Return repr(self).

property distance: float | None#

Pen distance from screen

property is_down: bool#

If pen is touching the screen

property is_hover: bool#

If the pen is hovering over the screen

property pressure: float | None#

Pen pressure

property previousDistance: float | None#

Previous distance of pen from screen

property previousPressure: float | None#

Previous pen pressure

property previousScreenPos: tuple[int, int] | None#

Previous screen coordinates

property previousTilt: tuple[int, int]#

Previous tilt of pen

property previousX: float | None#

Previous x coordinate

property previousY: float | None#

Previous y coordinate

property screenPos: tuple[int, int] | None#

screen coordinates

property tilt: tuple[int, int]#

Pen tilt

property was_down: bool#

If the pen was touching the screen in the previous event

property was_hover: bool#

If the pen was hovering over the screen in the previous event

property x: float | None#

x coordinate

property y: float | None#

y coordinate

class libremarkable.WaveformMode(value, names=None, *, module=None, qualname=None, type=None, start=1, boundary=None)#

Waveform mode to use during an update

__format__(format_spec, /)#

Default object formatter.

__new__(value)#
Grayscale = 3#

Grayscale mode

HighQualityGrayscale = 2#

High quality mode

Highlight = 8#

Highlight mode

Initialize = 0#

Initialize the framebuffer

Mono = 1#

Black and white mode

libremarkable.color_t#

alias of c_ushort

libremarkable.orientation()#

Get the current device orientation

Return type:

Orientation

class libremarkable.geometry.Point(x, y)#

Point on a 2d plane

__eq__(other)#

Return self==value.

__hash__()#

Return hash(self).

__init__(x, y)#
__iter__()#

Iterate through the x and then y coordinate

Return type:

Iterable[float]

Returns:

x and then y

__lt__(point)#

Check to see if one point is less than another point

Parameters:

point (Point) – point to compare against

Return type:

bool

Returns:

if the tuple of this point is less than the tuple of the point to compare against

__repr__()#

Return repr(self).

toInt()#

Return a clone of this point after converting the x and y coordinates to integers

Return type:

Point

__weakref__#

list of weak references to the object

x: float#

x coordinate

y: float#

y coordinate

class libremarkable.geometry.Rect(left, top, right, bottom)#

A rectangle on a 2d plane

__and__(rect)#

See intersect()

Return type:

Rect | None

__bool__()#

If the rectangle is valid

Return type:

bool

__contains__(point: libremarkable.geometry.Point)#
__contains__(rect: libremarkable.geometry.Rect)
__contains__(item)

If the rectangle contains a point or a rect

Parameters:

item (Point|Rect) – Point or rectangle to check

Return type:

bool

Returns:

If the point or rectangle is in this rectangle

__eq__(other)#

Return self==value.

__hash__()#

Return hash(self).

__init__(left, top, right, bottom)#
__iter__()#

Iterate through the left, top, right, and then bottom of the rectangle :rtype: Iterable[float] :return: left, top, right, then bottom of the rectangle

__lt__(point)#

If a point is less than the rectangle :type point: Point :param point:

Return type:

bool

__repr__()#

Return repr(self).

__sub__(rect)#

See difference()

Return type:

Iterable[Rect]

__xor__(rect)#

Returns the region without the intersect() of rect

Parameters:

rect (Rect)

Return type:

Region

difference(rect)#

Returns the difference of this rectangle and another rectangle

Parameters:

rect (Rect) – Rectangle to difference

Return type:

Iterable[Rect]

Returns:

Rectangles that make up the difference

intersect(rect)#

Returns the intersection of this rectangle and another rectangle

Parameters:

rect (Rect) – Rectangle to intersect

Return type:

Rect | None

Returns:

The intersection if there is any

intersects(rect)#

Check if a rectangle intersects this rectangle

Parameters:

rect (Rect) – Rectangle to compare with

Return type:

bool

Returns:

If they intersect

resize(width, height)#

resize the rectangle to a specific width and height, this resizes with topRight as the anchor-point

Parameters:
  • with – new width of the rect

  • height (float) – new height of the rect

resized(width, height)#

Clone the rect and then resize it to a specific width and height with the topRight as the anchor-point

Parameters:
  • with – width of the new rect

  • height (float) – height of the new rect

Return type:

Rect

Returns:

The resized rect

toInt()#

Clone and return a rect where left, top, right, and bottom have been converted into integers :rtype: Rect :return: Cloned rectangle with integer coordinates

translate(x, y)#

Move the rectangle on the 2d plane

Parameters:
  • x (float) – x coordinate translation

  • y (float) – y coordinate translation

translated(x, y)#

Clone the rect and then translate it on a 2d plane

Parameters:
  • x (float) – x coordinate translation

  • y (float) – y coordinate translation

Return type:

Rect

Returns:

The translated rect

__weakref__#

list of weak references to the object

property area: float#

The area of the rectangle

bottom: float#

bottom right y coordinate

property bottomLeft: Point#

The bottom left point of the rectangle

property bottomRight: Point#

The bottom right point of the rectangle

property center: Point#

The center point of the rectangle

property height: float#

The height of the rectangle

left: float#

top left x coordinate

right: float#

bottom right x coordinate

top: float#

top left y coordinate

property topLeft: Point#

The top left point of the rectangle

property topRight: Point#

The top right point of the rectangle

property width: float#

The width of the rectangle

class libremarkable.geometry.Region(*rects)#

A collection of rectangles

__add__(rect: libremarkable.geometry.Rect)#
__add__(rects: Iterable[libremarkable.geometry.Rect])
__add__(region: libremarkable.geometry.Region)
__add__(item)

Create a clone that adds one or more rect or a region to this region

Parameters:

item (Rect|Iterable[Rect]|Region) – Item to add to the cloned region

Return type:

Region

Returns:

clone merged with item

__contains__(point: libremarkable.geometry.Point)#
__contains__(rect: libremarkable.geometry.Rect)
__contains__(region: libremarkable.geometry.Region)
__contains__(item)

Checks if a point, rect, or region is contained in this region

Parameters:

item (Point|Rect|Region) – Item to compare

Return type:

bool

Returns:

If the item is contained in the region

__iadd__(rect: libremarkable.geometry.Rect)#
__iadd__(rect: Iterable[libremarkable.geometry.Rect])
__iadd__(region: libremarkable.geometry.Region)
__iadd__(item)

Add a rect or region to this region

Parameters:

item (Rect|Iterable[Rect]|Region) – Item to add to the region

Return type:

Self

__init__(*rects)#

Create a new instance

Parameters:

rects (list[Rect]) – Rectangles that make up this region

__isub__(rect: libremarkable.geometry.Rect)#
__isub__(rect: Iterable[libremarkable.geometry.Rect])
__isub__(region: libremarkable.geometry.Region)
__isub__(item)

Remove a rect or region from this region

Parameters:

item (Rect|Iterable[Rect]|Region) – Item(s) to remove

Return type:

Self

__iter__()#

Iterate through elements

Return type:

Iterable[Rect]

__len__()#

Number of elements in the region

Return type:

int

__repr__()#

Return repr(self).

Return type:

str

__sub__(rect: libremarkable.geometry.Rect)#
__sub__(rect: Iterable[libremarkable.geometry.Rect])
__sub__(region: libremarkable.geometry.Region)
__sub__(item)

Create a clone of the region and then remove the rect(s) from the clone

Parameters:

item (Rect|Iterable[Rect]|Region) – Item(s) to remove

Return type:

Region

Returns:

clone without the rect(s)

add(rect)#

Add a rect to the region

Parameters:

rect (Rect) – rect to add

Return type:

None

discard(rect)#

Remove a rectangle from the region.

Return type:

None

__weakref__#

list of weak references to the object

property boundingRect: Rect#

Get a rectangle that contains all the rectangles in the region

elements#

Rectangles that make up the region

property toInt: Region#

Create a clone and convert all rects in the clone to integer coordinates