python power

the power of python's libraries
python and it's libraries

I've said before that Python, why we've chosen it as our primary development language and why it is instrumental in our endeavor to engineer innovative and affordable financial software before. However, since our goal is to create software that will considerably narrow (closing it completely is pretty much impossible) the gap between individual and insitutional investors, it is fair to wonder if a startup team - with a minimum of resources - can achieve that. Let's take a closer look. Hopefully, the following article should give you a bit of confidence that it is indeed.

While the true power of Python is (more than) the sum of its parts and not just one factor (I'm confident that there's a language that's better in any give single area, but none that can truly rival it as a whole). A big part of that is the huge community of developers and the resources they've created on the Web, but another crucial part - one that made Python's adoption as out primary development language an easy choice - are it's many (litarally thousands) of libraries - most of which come with generous license agreements, making them suitable for closed-source development. I want to give you some concrete examples to illustrate the power of Python in conjuction with both its standard library (included with every distribution) and third party libraries. In a nutshell: it is extremely powerful, letting you do in weeks what would take years in C++ (at least if you're starting from scratch like we are). After all, it is the obvious choice for independent developers around the world for a reason.

The following are some of the libraries I've had a chance to use so far. Since I'm using the official Python logo, I must point out that - except for the standard library - none of the other libraries in this post are directly related to Python - the programming language - itself. They 'just' extend its functionality and are authored by people unrelated to the Python language. The libraries referenced in this post might also include wrappers, interfaces and modules. While there are clear distinctions in theory, in practice it's far from being black and white. If you're considering Python as a programming language - or are curious about all the stuff you can do with it - you might find this interesting regardless of your technical expertise. This article was also written to give you a look into the heart and soul of what we are are doing. As you can see, we've been busy...

After reviewing some Python books, I decided to write a paragraph or two about the cool libraries we've been using (privately and for our project). Libraries are a big reason why we've chosen Python as our primary programming language: having a well-supported library to do the hard things - and a generous license to go with it - makes life so much easier! Let's take a look in alphabetical order:

The Standard Library
As the name says, this is the standard library that ships with Python. Unlike the standard library of most other programming languages, the Python standard library is incredibly powerful and versatile by itself, hence the motto: 'Batteries Included'. I'll give you some examples of what it can do (the choices being arbitrary).

  • csv
    This is a great example of why we love Python so much: as much as you might hate certain design-decisions of Python, nothing comes even close to offering this kind of functionality out of the box. In this case, if you're looking to work with CSV (Comma Separated Values) files - Python has you covered, right out of the box... batteries included!
  • hashlib
    If you need to deal with hashes - no matter what type - hashlib is the way to go. Except for the obsolete CRC32 and Adler32 (for which you'll need zlib) hashlib's got you covered. Checksums have never been easier! As I was using this for a little project, I realized that - ironically - computing checksums is one of the few things for which lower-level languages (e.g. C++) are better suited than Python. I won't go into the details, let's just say that doing this work by hand (in Python) would have been a nightmare. Fortunately, hashlib took care of all my needs and I've never looked back. It does what it is supposed to do, and it does it well - for example by using a common constructor for all the hashing algorithms (with a few - as in one or two, depending on how you count) exceptions for purely mathematical reasons. I'll never get tired of mentioning generous license agreements: just because something is opensource doesn't mean it'll be suitable  for whatever you have in mind. I'm a big fan of BSD and MIT-style licenses which, in a nutshell, let you do pretty much anything you may want to (including employing them in proprietary software). These guys (and everyone else releasing his or her work under a similarly permissive license) are awesome!
  • zlib
    To be honest, I haven't dug into this one very much (yet) and have not used it for it's primary purpose, which is compression and decompression (as in "zip file"). In my defense, it is part of the Python distribution itself. With zlib you can easily read  and write compressed - a.k.a. archived - data. Namely zlib-encryption based data. Which, to make things confusing for non-technical people, isn't the same as zip. Normally, the compressed data is further "wrapped" into a .gzip or .zlib wrapper. Though, even that is not yet quite a file you could send to a friend. The important point here is that the hard work has been done. The underlying algorithm is the same for a several different file extensions which, essentially mean nothing (they are for you and me, only in some cases the computer). But all of this is beside the point... the takeaway here is that Python, "out of the box", comes equipped with powerful data compression features. In case you need more flexibility, or a  different algorithm, I'm pretty sure there's a library for that as well. As mentioned above, zlib is also responsible for computing CRC32 and Adler-32 checksums.

    As you can see, for a lot of jobs you don't have to look any further than the standard library. For what it's worth: the documentation is excellent too, so when in doubt the answer is only a couple of clicks away.

    If what you need isn't included in the Python Standard Library, chances are good someone else has done the job for you. Licenses vary, but all of the following are free to use for both proprietary and open-source projects. What more can you ask? (Note that some libraries have less generous licenses and are not suitable for proprietary software. If this is an issue for you, be sure to check if there are alternatives.)

  • ConfigObj
    This is one of those little gems that you find by accident. Shall you ever need to  read or write configuration files: ConfigObj is the way to go. Python itself offers a comparable system for configuration files, which works just fine for standard things, but if you need something slightly different you'll wish you went with ConfigObj instead. It's simple, it's elegant and it's covered by a generous license: what more can you desire? Your biggest - and only - headache will be managing the user interface. Everything else is handled by ConfigObj. Whatever it is you're trying to do (with configuration files) you simply can't go wrong giving ConfigObj a try!

  • datetime and pytz
    Although 'datetime' is part of the Standard Library, 'pytz' is not. Since they are closely related in functionality - and often used together - I've decided to give them a shared entry. One of us decided to use this for a little private project: suffice to say that whatever you'll ever be tempted to do with dates and / or time (e.g. converting from one time zone to another while taking into account (the ugly cancer that is) daylight saving time these two libraries got you covered. A heads up: we've encountered some minor issues when deploying the resulting program on a Windows 10 platform with Kaspersky Antivirus. A corner case one might say, still - it's something you might want to fix if you'll ever find yourself in the situation of deploying software built with this library.

  • Tkinter / Tk
    Tkinter is the closest thing to a built-in windows manager in Python. In recent version, it actually is fully built-in and you can use it out of the box. So, if you're looking for something that 'just works', tk(inter) is probably the way to go. There are several alternatives: one is mentioned below, while the others still need to be investigated. However, in my humble opinion Tkinter and wxPython are the only real options for GUIs in Python. Everything else has GPL/LGPL licenses, which means it's not suited to propietary development. Tkinter and wxPython are. In case you've been wondering, tkinter has gotten a lot of bad publicity - probably fairly so - but recent versions have done away with most of the problem-areas. Although you might take issue with it's programming paradigms (depending on your expectations), it has it's advantages. If you're looking to build a simple user interface quickly, Tkinter/Tk might be the way to go. Personally, I find it's biggest issue to be the lack of Python-specific and up-to-date documentation, along with some missing features like "Drag & Drop" that need to be implemented through separate libraries. If you're wondering whether Tkinter or wxPython offer the better GUI: it's a not even a contest. wxPython wins in every regard, except for the (perceived) complexity. Unlike wxPython, tk does its best to hide all the complexity from the user. As all grey-bearded programmers know, that cuts both ways. While it makes it (somewhat) easier for novices to get started, it also makes it a huge headache to figure out why something isn't working the way it should. Still, it's free, it comes bundled with your installation of Python 3 so we should be grateful...  For simple user interfaces, Tkinter/Tk will do the job just fine. If you don't like it, you can always move on to wxPython. The main drawback to using Tkinter/Tk is that, unlike wxPython, it doesn't offer fine-grained control and has a lot of legacy-baggage and a number of limitations. If you can live with that, it's an excellent way to quickly code a presentable GUI that works on all the major platforms (Windows, macOS and Linux).

  • wxPython
    The gold standard of windows managers. Trust me when I say that nothing comes close to it: completely native user interface (at least for Windows, macOS and Linux) are at your disposal. The downside? It's a port (originally a wrapper) from C++ - so don't expect Pythonic convenenience when working with it. More often than not, most of your code will consist of user-interface related things but, to be fair, that is not unique to wxPython. It just happens that user-interfaces take up a lot of code in most applications. That being said, the amount of control and the result itself are incomparable to its competitors. If you're serious about developing GUI's (written in Python) this is the way to go! Fortunately there are a lot of good tutorials to make things easier. Among them, the amazing stuff written by Jan Bodnar (check out "what we've been reading page" for a link).

I hope the above is useful to someone or, at least, makes it clear why we've  decided to use Python as our main programming language. Had we settled on the closest competitor (C++) I wouldn't have time to write this and hit milestones at the same time!  

As far as coding goes, life has never been better.

If you're looking to start writing Python, don't bother with version 2.x - it's been a (compatibility) issue for long enough but now 99% of what's out there (and not completely outdated) supports Python 3.x! I just mention this because it was a the main reason not to use Python in one of my previous projects: languages with incompatible versions are a nightmare, but if they survive the transition they come out stronger than ever.

If you need support, assistance, or a consultation of any kind, involving these libraries - or Python itself - don’t hesitate to contact us. We'll be more than happy to work with you.