Tweeting from the Command Line with Twyt

When 140 characters is all you need, the command line does it better.

As you’ve probably realized by now, I love the command line. Part of the reason for my obsession with the command line is that I work at the command line for most of every day at my day job. With the exception of the few Windows hosts to which I must connect for certain operations, I never see a graphical interface. And, in keeping with my need to stay command line connected, I sought out a command line Twitter client to help me stay current with my all-important Twitter statuses. I chose the somewhat obscure, Python-based Twyt project to use as my Twitter companion.

I don’t care much for social networking but I submit that it is the way of the world and so, I reluctantly conform to what’s current. I wouldn’t want to deprive my followers (Twits?) of knowing what I had for breakfast nor would I want to deprive myself of the vital goings on of those whom I follow. Since I have little time (or tolerance) for chasing the web-based Twitter client, I decided to use the command line client for all my Twitter-based interactions—and of course to keep up with the multitude of tempting multilevel marketing opportunities tossed my way on an hourly basis.


I can often be a Linux purist and prefer to install from source. Fortunately, the developer provides the source tarball for those of us Ludites who either use a distribution that doesn’t incorporate Twyt or who are control freaks and must know what’s going on and have the option to alter it. It’s also for those of us who love to chase endless dependencies and then complain about them later.

For those of you who, instead, use packaging systems, you need python, python-simplejson and python-twyt. The rest of us will have to install the dependencies first, then download the tarball from the Twyt Download Repository and run the installation script at a command line.

# setup.py install

Once you’ve installed the dependencies and the Twyt package itself, you’re ready to update your throng of panting followers of your latest conquests and adventures.

Tweeting with Twyt

Broadcasting your breaking news bits is a simple task. It’s no more difficult than tweeting on the Twitter site or using some other third-party tweet application and help is at your fingertips. Let’s start by looking at that list of commands and finding help.

$ twyt --commands

usage: twyt  COMMAND [options] [args]

Available commands:
 accountlimit Show the API rate limit for your Twitter account.
        block Blocks a user specified by ID (numerical ID or screen name)
       delete Deletes a tweet by ID
       direct Sends a direct message to another user
    directdel Delete a direct message which was sent to you
   directsent Prints the 20 last direct messages sent by you
     directtl Prints the 20 last direct messages sent to you
    friendstl Returns 20 most recent statuses in your friends timeline
      iplimit Show the API rate limit for your IP address.
    namecache Access and manipulate the username cache.
     publictl Shows the 20 most recent statuses in Twitter's public timeline
      replies Lists statuses which are replies to you (statuses with @yourusername in them)
         show Show a single status message by ID
         sing Similar to 'tweet', wraps the status in musical notes
        tweet Updates the authenticating user's Twitter status
      unblock Unblocks a user specified by ID (numerical ID or screen name)
         user Get and set Twyt user options, e.g. remembered passwords and Twitter usernames
       usertl Show your timeline, or USERNAME's timeline

For command-specific help, use twyt COMMAND --help

Use the tweet command to send a new message. You must surround your message in double quotes.

$ twyt tweet "Hello, everyone, catch this article Monday on Linux Magazine at linux-mag.com" –u kenhess

Enter kenhess's Twitter password:

[8782187385] kenhess: Hello, everyone, catch this article Monday on Linux Magazine at linux-mag.com (Sun Feb 07 22:43:14 2010 via Twyt)

To prevent the constant prompting for your password when you enter a command, you can enter it on the command line with your tweet or other commands with your username:

$ twyt tweet "Hello, everyone, catch this article Monday on Linux Magazine at linux-mag.com" –u kenhess –p SuperSecretPassword

[8782187385] kenhess: Hello, everyone, catch this article Monday on Linux Magazine at linux-mag.com (Sun Feb 07 22:43:14 2010 via Twyt)

To set your username and password permanently, use the following command:

$ twyt user –user=kenhess set

Enter kenhess's Twitter password:

This action saves your username and password to a hidden file in your home directory named .twytrc.json. You can now use twyt without specifying your username or password.

Microblogging Culture

Unless you’ve hidden yourself away in a non-Internet connected Monastery for the past few years, Twitter is computing’s newest rage of the age. Whatever you can say in 140 characters or less, capture’s the ever-shortening attention spans of your followers. Followers are people who care enough about you to read your tweets (your short messages posted to twitter.com). You, in turn, follow people you care about but can only tolerate in short blasts.

This 140 character microblogging is for those of us too busy for Facebook, phone calls or text messages. We want the latest news and information without all the annoying details. When you want to know who’s recently clipped their toenails, who’s attending a Tea Party or who’s breaking up with their girlfriend; Twitter is the place to catch it all.

The basic rule of Twitter: If you can’t say it in 140 characters or less, no one cares, because you can’t say it on Twitter.

Tweeting, for some, is a way of life. I use it to promote stories, like this one, and to keep track of important announcements and news bits from a select few (1,600 or so at last count) of my closest friends and colleagues. Twyt is only one of a few different command line Twitter clients but it is one of the best I’ve seen and the only one I use with regularity. I appreciate its ease of use, small footprint and few dependencies. Twyt is such a pleasure to use, it almost makes me enjoy using Twitter. In just the time it took me to write this article, I’ve missed almost 400 updates and I must catch up—at the command line, of course. Happy tweeting.

Comments on "Tweeting from the Command Line with Twyt"


Surely something on the lines of
curl -u user:pass -d status=\”Your message here\” http://twitter.com/statuses/update.json is just as easy ??


I did something like this a little while ago, in python, not this functional anyway. http://fossix.org/node/8


Twitter still sucks. No CLI Twitter client is going to fix that.


Follow & Unfollow commands seem to be missing.


@symeonb that would be a little less secure because anyone could read your ~/.bash_history and find your password.



If other people can read your .bash_history file, your Twyt password is the least of your problems.



Can you save your user and passwd? curl works but not as conveniently and you don\’t have the other features.


Yes, it\’s not perfect but it gives someone busy an opportunity to tweet from the command line at any moment of the day.


If you have two twitter accounts it might be a way to get informed about any alert or important event that is generated on your linux platform. Obviously, as a direct message. Anyway, I don\’t know if you can automatize the dispatch of messages with this APP, but if you can do that, it could be useful…


Most useless feature of the decade.


    To TGGP:"John Sabotta:I should have expected such a video from you. For an actual video of Hanson in a debate, see Liberty vs Efyt&iencf.cquoi;I took a look. Albert Speer, Jr.


I\’ve been a no-Twitter Luddite, but my environment is like Ken\’s — so twyt could do it! Let\’s see… once I have thousands of followers breathless to know what I\’m eating, I could write a loop:

for food in cereal toast \”an orange\”; do
twyt tweet \”It\’s $(date +%R) and now I\’m eating $food. How exciting!\”
sleep 200


while read food
do twyt tweet \”It\’s $(date +%R) and now I\’m eating $food. How exciting!\”




I love that and I might steal it for my own evil purposes.


If you just can\’t say it all in 140 characters, how about a little script that reads your input from keyboard, pipe, or files… uses fmt to break it into tweets of 140 characters or less… then blasts out the tweets with a one-second delay between?

# twitter_splitter – read file(s) or stdin,
# output as tweets of 140 characters or less

fmt -w 140 \”$@\” |
while read line; do
twyt tweet \”$line\” -u \”$user\”
sleep 1

If you pipe fmt output through tac (reverse cat), the tweets would come out in reverse order.