Text Builder (rich text)

class atproto_client.utils.text_builder.TextBuilder

Bases: object

Helper that helps construct rich text.

There are three facets: link, mention, tag.

Each facet could be linked to text segment.

This helper provides chained API.

Example

Without chaining:

>>> from atproto import client_utils
>>> text_builder = client_utils.TextBuilder()
>>> text_builder.tag('This is a rich message. ', 'atproto')
>>> text_builder.text('I can mention ')
>>> text_builder.mention('account', 'did:plc:kvwvcn5iqfooopmyzvb4qzba')
>>> text_builder.text(' and add clickable ')
>>> text_builder.link('link', 'https://atproto.blue/')

With chaining:

>>> from atproto import client_utils
>>> text_builder = client_utils.TextBuilder().text('Test msg using ').link('Python SDK', 'https://atproto.blue/')

Later you can use this builder in the Client:

>>> from atproto import Client, client_utils
>>> client = Client()
>>> # You can pass instance of TextBuilder instead of str to the "text" argument.
>>> client.send_post(client_utils.TextBuilder().link('Python SDK', 'https://atproto.blue/'))
>>> # Same with send_image method

Note

This helper doesn’t support overlapped features (features at the same byte range).

build_facets() List[Main]

Build facets from the current state of the builder.

build_text() str

Build text from the current state of the builder.

Add link to the builder.

Parameters:
mention(text: str, did: str) TextBuilder

Add mention to the builder.

Parameters:
  • text – Text of the mention.

  • did – Valid DID. For example, did:plc:kvwvcn5iqfooopmyzvb4qzba

tag(text: str, tag: str) TextBuilder

Add tag to the builder.

Parameters:
  • text – Text of the tag.

  • tag – Hashtag.

text(text: str) TextBuilder

Add text to the builder.

Parameters:

text – Text.