API

This chapter documents twtxts API and source code internals.

Models

class models.Tweet(text, created_at=None, source=None)[source]

A Tweet represents a single tweet.

Parameters:
  • text (str) – text of the tweet in raw format
  • created_at (datetime) – (optional) when the tweet was created, defaults to now() when no value is given
  • source (Source) – (optional) the Source the tweet is from
absolute_datetime

Return human-readable absolute time string.

relative_datetime

Return human-readable relative time string.

class models.Source(nick, url=None, file=None)[source]

A Source represents a twtxt feed, remote as well as local.

Parameters:
  • nick (str) – nickname of twtxt user
  • url (str) – URL to remote twtxt file
  • file (str) – path to local twtxt file

Config

Every supported option of twtxt is made available as a property of the Config object. To find out the meaning of those check Configuration.

class config.Config(config_file, cfg)[source]

Config interacts with the configuration file.

Parameters:
add_source(source)[source]

Adds a new Source to the config’s following section.

build_default_map()[source]

Maps config options to the default values used by click, returns dict.

check_config_sanity()[source]

Checks if the given values in the config file are sane.

classmethod create_config(cfgfile, nick, twtfile, twturl, disclose_identity, add_news)[source]

Create a new config file at the default location.

Parameters:
  • cfgfile (str) – path to the config file
  • nick (str) – nickname to use for own tweets
  • twtfile (str) – path to the local twtxt file
  • twturl (str) – URL to the remote twtxt file
  • disclose_identity (bool) – if true the users id will be disclosed
  • add_news (bool) – if true follow twtxt news feed
classmethod discover()[source]

Make a guess about the config file location an try loading it.

following

A list of all Source objects.

classmethod from_file(file)[source]

Try loading given config file.

Parameters:file (str) – full path to the config file to load
get_source_by_nick(nick)[source]

Returns the Source of the given nick.

Parameters:nick (str) – nickname for which will be searched in the config
options

A dict of all config options.

remove_source_by_nick(nick)[source]

Removes a Source form the config’s following section.

Parameters:nick (str) – nickname for which will be searched in the config
write_config()[source]

Writes self.cfg to self.config_file.