Yourls URL Shortener for Turpial

Maybe you know Yourls, a pretty cool URL shortener which you can set up on your own server very easily. Link shorteners are nice to have because

  1. you can share long links with short urls and
  2. you can view and organise all links you ever shared (incl. statistics and so on).

There are many alternatives like, and so on, but Yourls belongs to YOU and you don’t have to pay attention to ToS changes or the provider’s financial status. AND you can use whichever domain you own, for example in my case it’s

And maybe you also know Turpial, a Twitter client for GNU/Linux systems (I don’t like Twitter’s web page). Until lately I used Choqok, a KDE optimised client, but there were many things which annoyed me: No image previews, slow development, unconvenient reply behaviour and so on. And hey, why not trying something new? So I started to use Turpial which seems to solve all these critic points. Well, like always I missed some preferences to configure. But since it’s Free Software, one is able to look how the software works and to change it – and to share the improvements which I’ll do in the next step!

Turpial already offers some link shorteners but not Yourls. But we can add it manually. To do so, open the file /usr/lib/python2.7/dist-packages/libturpial/lib/services/url/shortypython/ as root. Now add the following somewhere between the already existing shorteners

# Yourls
class Yourls(Service):
	def shrink(self, bigurl):
		resp = request('http://YOUR_DOMAIN/yourls-api.php', {'action': 'shorturl', 'format': 'xml', 'url': bigurl, 'signature': 'YOUR_SIGNATURE'})
		returned_data =
		matched_re ='(http://YOUR_DOMAIN/[^"]+)', returned_data)
		if matched_re:
			raise ShortyError('Failed to shrink url')
yourls = Yourls()

Just replace YOUR_DOMAIN and YOUR_SIGNATURE accordingly. The usage of a signature enables you to hide your username and password when sending the shorten requests, like an API key and looks like f51qw35w6 (more about passwordlessAPI). You can retrieve your signature on your Yourls‘ Admin page via Tools.

Then add the new service to the list of shorteners. In the same file search for services = { (on the bottom) and add somewhere in the following list:

'yourls-instance': yourls,

Well, then just restart Turpial, go to Preferences > Services and choose yourls-instance from the list of Short URL services. Congrats, you should be able to short your URLs with Yourls in Turpial now :)

Any problems or improvements? Drop me a message!


  • For me, only hardcoding the signature worked but not the prompt for these data like in some other services stated in the file
  • Another file worth your attention might be /usr/lib/python2.7/dist-packages/turpial/ui/qt/templates/style.css. There you can change colors, fonts and so on. For example, the Ubuntu font wasn’t installed on my system so I just chose Sans Serif instead.