Contents Menu Expand Light mode Dark mode Auto light/dark, in light mode Auto light/dark, in dark mode Skip to content
Snip-python documentation
Light Logo Dark Logo
Snip-python documentation
  • Quickstart
  • Command Line Interface (CLI)
    • Token Management
    • Snippets
  • Snippets
    • Image Snippet Guide
    • Text Snippet Guide
    • Combining different snippets
    • Link Snippet Guide
  • Access Tokens
  • WebApi Wrapper
    • Book Endpoints
    • Account Endpoints
  • Reference
    • snip.token
      • snip.token.storage
        • snip.token.storage.file_store
        • snip.token.storage.keyring_store
      • snip.token.token
        • snip.token.token.AccountToken
        • snip.token.token.BookToken
        • snip.token.token.Token
    • snip.snippets
      • snip.snippets.array
        • snip.snippets.array.ArraySnip
      • snip.snippets.base
        • snip.snippets.base.BaseSnip
      • snip.snippets.factory
      • snip.snippets.image
        • snip.snippets.image.ImageSnip
      • snip.snippets.link
        • snip.snippets.link.IconStyle
        • snip.snippets.link.LinkSnip
      • snip.snippets.text
        • snip.snippets.text.TextSnip
        • snip.snippets.text.TextStyles
    • snip.api
      • snip.api.account
        • snip.api.account.Group
        • snip.api.account.GroupMember
        • snip.api.account.MemberRoleUpdate
      • snip.api.books
        • snip.api.books.BasePermissionTypedDict
        • snip.api.books.BookTypedDict
        • snip.api.books.GroupPermissionTypedDict
        • snip.api.books.UserPermissionTypedDict
      • snip.api.exceptions
      • snip.api.request
      • snip.api.schemas
      • snip.api.snippets
      • snip.api.token
        • snip.api.token.TokenMetadata
Back to top
View this page

snip.snippets.link.LinkSnip¶

class snip.snippets.link.LinkSnip(snip: S, href: str, **kwargs)¶

Test link snip.

Attributes

book_id

The identifier of the book the snippet belongs to

deployment

The deployment URL of the snippet

bounding_box

The bounding box of the snip.

height

The height of the snip.

icon_style

inner

Get the inner snip.

mirror

The mirror of the snip.

pos

Position of the snippet on a page.

rotation

The rotation of the snip.

schema

Schema to validate the snippet.

size

The size of the snip.

type

The type identifier of the snippet e.g. 'text', 'image' etc.

width

The width of the snip.

x

The x-coordinate of the snip.

y

The y-coordinate of the snip.

snip

href

Methods

__init__(snip, href, **kwargs)

Create a new snippet.

as_json([validate])

Return the snippet as a dictionary in basic snippet json format.

preview([token])

Generate a snippet preview.

upload([book_id, token, validate])

Upload the snippet to the labbook.

__init__(snip: S, href: str, **kwargs)¶

Create a new snippet.

Parameters:
  • book_id (int, optional) – The book_id of the snippet. Defaults to None. If None, the snippet book_id is derived from the token.

  • deployment (str, optional) – The deployment URL of the snippet. Defaults to None. If None, the deployment is set to the default deployment.

as_json(validate=True) → dict¶

Return the snippet as a dictionary in basic snippet json format.

Returns a dict in the basic snippet structure.

{
    "book_id": 123
    "type": "text"
    "data": {}
    "view": {}
}

If the schema is set in the class it is used to validate the snippet data before returning it.

Parameters:

validate (bool, optional) – If True, the snippet is validated against the schema. Defaults to True.

Raises:

jsonschema.ValidationError – If the snippet does not match the schema.

book_id: int | None¶

The identifier of the book the snippet belongs to

property bounding_box¶

The bounding box of the snip.

Returns the bounding box of the nested snip.

deployment: str | None¶

The deployment URL of the snippet

property height¶

The height of the snip.

Returns the height of the nested snip.

property inner: S¶

Get the inner snip.

property mirror¶

The mirror of the snip.

Returns the mirror of the nested snip.

property pos: Tuple[float, float] | None¶

Position of the snippet on a page.

Returns none if the position is not set yet.

preview(token: Token | None = None, **kwargs) → Image | None¶

Generate a snippet preview.

This requests a server side rendering of the snippet and returns the preview image.

Returns:

  • token (Token) – The token to use for the request. If None, the token gets inferred if possible.

  • **kwargs (Any) – Additional keyword arguments to pass to the requests function.

property rotation¶

The rotation of the snip.

Returns the rotation of the nested snip.

property schema: dict | None¶

Schema to validate the snippet.

The schema is used to validate the snippet and should be a valid jsonschema.Draft202012Validator schema.

Returns:

The schema for this snippet class if available. If none is available, None is returned and the schema functionality is disabled.

Return type:

schema

property size¶

The size of the snip.

Returns the size of the nested snip.

type: str = 'link'¶

The type identifier of the snippet e.g. ‘text’, ‘image’ etc.

upload(book_id: int | None = None, token: BookToken | None = None, validate=True, **kwargs)¶

Upload the snippet to the labbook.

This method uploads this snippet to a labbok given the snippets book_id and deployment url.

If no token is provided, the token is inferred from the book_id and deployment.

Parameters:
  • book_id (int, optional) – The book_id of the snippet. Defaults to None. If None, the snippet book_id is derived

  • token (Token) – The token to use for the request. If None, the token gets inferred if possible.

  • validate (bool, optional) – Weather to validate the snippet before uploading. Defaults to True.

  • **kwargs (Any) – Additional keyword arguments to pass to the requests function.

property width¶

The width of the snip.

Returns the width of the nested snip.

property x¶

The x-coordinate of the snip.

Returns the x-coordinate of the nested snip.

property y¶

The y-coordinate of the snip.

Returns the y-coordinate of the nested snip.

Next
snip.snippets.text
Previous
snip.snippets.link.IconStyle
Copyright © 2024, Sebastian B. Mohr
On this page
  • snip.snippets.link.LinkSnip
    • LinkSnip
      • LinkSnip.__init__()
      • LinkSnip.as_json()
      • LinkSnip.book_id
      • LinkSnip.bounding_box
      • LinkSnip.deployment
      • LinkSnip.height
      • LinkSnip.inner
      • LinkSnip.mirror
      • LinkSnip.pos
      • LinkSnip.preview()
      • LinkSnip.rotation
      • LinkSnip.schema
      • LinkSnip.size
      • LinkSnip.type
      • LinkSnip.upload()
      • LinkSnip.width
      • LinkSnip.x
      • LinkSnip.y