{"id":7282,"date":"2021-08-19T10:32:37","date_gmt":"2021-08-19T09:32:37","guid":{"rendered":"https:\/\/www.blopig.com\/blog\/?p=7282"},"modified":"2021-08-31T16:30:20","modified_gmt":"2021-08-31T15:30:20","slug":"a-handful-of-lesser-known-python-libraries","status":"publish","type":"post","link":"https:\/\/www.blopig.com\/blog\/2021\/08\/a-handful-of-lesser-known-python-libraries\/","title":{"rendered":"A handful of lesser known python libraries"},"content":{"rendered":"\n<p>There are more python libraries than you can shake a stick at, but here are a handful that don&#8217;t get much love and may save you some brain power, compute time or both.<\/p>\n\n\n\n<p><a href=\"https:\/\/google.github.io\/python-fire\/guide\/\">Fire<\/a> is a library which turns your normal python functions into command-line utilities without requiring more than a couple of additional lines of copy-and-paste code.  Being able to immediately access your functions from the command line is amazingly helpful when you&#8217;re making quick and dirty utilities and saves needing to reach for the nuclear approach of using <a href=\"https:\/\/docs.python.org\/3\/library\/getopt.html\">getopt<\/a>.<\/p>\n\n\n\n<!--more-->\n\n\n\n<p><a href=\"https:\/\/alpha.iodide.io\/\">Pyodide <\/a>provides a way of running python in your web browser.  &#8220;So what?&#8221; you may ask, I&#8217;ve already got jupyter notebooks, colab etc.   Pyodide is different, it runs SOLELY in your browser, there&#8217;s no back end server.  Not just that, it runs python <strong>and<\/strong> the huge suites of the C libraries that actually make python useful (think NumPy, Pandas, Matplotlib, SciPy, scikit-learn etc.) by converting them into webkit\/javascript\/html so that your code runs completely within in the browser and has access to the browser\u2019s APIs.  <\/p>\n\n\n\n<p><a href=\"http:\/\/modin.org\/\">Modin<\/a> is an embarrassment* of pandas and they&#8217;re on steroids.  Pandas can only utilise a single CPU core, no matter how many are available; modin on the other hand will automatically parallelise across as many as you&#8217;ve got.  When using modin, often the biggest change you&#8217;ll need to make to your code is:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">#import pandas as pd<br>import modin.pandas as pd<\/pre>\n\n\n\n<p>Whilst modin doesn&#8217;t re-implement everything which pandas can do, the authors say it <a href=\"https:\/\/github.com\/modin-project\/modin\">covers<\/a> all of the most commonly used functions such as pd.read_csv with <a href=\"https:\/\/modin.readthedocs.io\/en\/latest\/_images\/read_csv_benchmark.png\">significant<\/a> speed-ups and &gt;90% of all the bells and whistles found in pd.DataFrame. <\/p>\n\n\n\n<p>* It would <a href=\"https:\/\/www.independent.co.uk\/arts-entertainment\/art\/features\/talk-animals-art-and-humour-collective-noun-2142716.html\">appear<\/a> the collective noun for pandas is an embarrassment.<\/p>\n\n\n\n<p><a href=\"https:\/\/openpyxl.readthedocs.io\/en\/stable\/\">Openpyxl<\/a> allows you to read and write Microsoft Excel xlsx workbooks.  Sooner or later someone&#8217;s going to take your carefully curated output and cram it into Excel, or hand you an Excel spreadsheet full of raw data (with or without <a href=\"https:\/\/www.blopig.com\/blog\/2020\/10\/the-right-tool-for-the-job-the-joy-of-excel\/\">formatting errors<\/a>).  Excel isn&#8217;t going away and you&#8217;re not going to get away from it, so why not grudgingly embrace it like a slightly racist elderly relative?<\/p>\n\n\n\n<p><a href=\"https:\/\/pypi.org\/project\/colorama\/\">Colorama<\/a> allows you to trivially add a splash of colour to your terminal output.  Whilst you could of course do this by printing <a href=\"https:\/\/en.wikipedia.org\/wiki\/ANSI_escape_code\">ANSI escape sequences<\/a> you&#8217;ve got to admit they&#8217;re no where near as user friendly as the Colorama version.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">#Colorama\nfrom colorama import Fore, Back, Style\nprint(Fore.RED + 'some red text')\n\n#ANSI version\nprint(\"\\u001b[31msome red text\\033[0m\")<\/pre>\n\n\n\n<p><\/p>\n\n\n\n<p><a href=\"https:\/\/www.geeksforgeeks.org\/turtle-programming-python\/\">Turtle <\/a>is everything which matplotlib isn&#8217;t.  If you don&#8217;t want to spend your time having a turtle crawl about your screen drawing your graphs, you&#8217;re just wrong.  The python Turtle can also draw geometric figures:<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><a href=\"https:\/\/i0.wp.com\/www.blopig.com\/blog\/wp-content\/uploads\/2021\/08\/turtle-trees-1024x518-1.jpg?ssl=1\"><img data-recalc-dims=\"1\" decoding=\"async\" width=\"625\" height=\"316\" loading=\"lazy\" src=\"https:\/\/i0.wp.com\/www.blopig.com\/blog\/wp-content\/uploads\/2021\/08\/turtle-trees-1024x518-1.jpg?resize=625%2C316&#038;ssl=1\" alt=\"\" class=\"wp-image-7292\" srcset=\"https:\/\/i0.wp.com\/www.blopig.com\/blog\/wp-content\/uploads\/2021\/08\/turtle-trees-1024x518-1.jpg?w=1024&amp;ssl=1 1024w, https:\/\/i0.wp.com\/www.blopig.com\/blog\/wp-content\/uploads\/2021\/08\/turtle-trees-1024x518-1.jpg?resize=300%2C152&amp;ssl=1 300w, https:\/\/i0.wp.com\/www.blopig.com\/blog\/wp-content\/uploads\/2021\/08\/turtle-trees-1024x518-1.jpg?resize=768%2C389&amp;ssl=1 768w, https:\/\/i0.wp.com\/www.blopig.com\/blog\/wp-content\/uploads\/2021\/08\/turtle-trees-1024x518-1.jpg?resize=624%2C316&amp;ssl=1 624w\" sizes=\"auto, (max-width: 625px) 100vw, 625px\" \/><\/a><figcaption>Fractal trees using turtle, from https:\/\/www.geeksforgeeks.org\/y-fractal-tree-in-python-using-turtle\/<\/figcaption><\/figure>\n\n\n\n<figure class=\"wp-block-image size-full\"><a href=\"https:\/\/i0.wp.com\/www.blopig.com\/blog\/wp-content\/uploads\/2021\/08\/Turtle-Spiral-1.png?ssl=1\"><img data-recalc-dims=\"1\" decoding=\"async\" width=\"625\" height=\"559\" loading=\"lazy\" src=\"https:\/\/i0.wp.com\/www.blopig.com\/blog\/wp-content\/uploads\/2021\/08\/Turtle-Spiral-1.png?resize=625%2C559&#038;ssl=1\" alt=\"\" class=\"wp-image-7294\" srcset=\"https:\/\/i0.wp.com\/www.blopig.com\/blog\/wp-content\/uploads\/2021\/08\/Turtle-Spiral-1.png?w=702&amp;ssl=1 702w, https:\/\/i0.wp.com\/www.blopig.com\/blog\/wp-content\/uploads\/2021\/08\/Turtle-Spiral-1.png?resize=300%2C268&amp;ssl=1 300w, https:\/\/i0.wp.com\/www.blopig.com\/blog\/wp-content\/uploads\/2021\/08\/Turtle-Spiral-1.png?resize=624%2C558&amp;ssl=1 624w\" sizes=\"auto, (max-width: 625px) 100vw, 625px\" \/><\/a><\/figure>\n","protected":false},"excerpt":{"rendered":"<p>There are more python libraries than you can shake a stick at, but here are a handful that don&#8217;t get much love and may save you some brain power, compute time or both. Fire is a library which turns your normal python functions into command-line utilities without requiring more than a couple of additional lines [&hellip;]<\/p>\n","protected":false},"author":15,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"nf_dc_page":"","wikipediapreview_detectlinks":true,"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"ngg_post_thumbnail":0,"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[29,14,138,227,272,15,393],"tags":[],"ppma_author":[507],"class_list":["post-7282","post","type-post","status-publish","format-standard","hentry","category-code","category-howto","category-journal-club","category-python-code","category-software-services","category-technical","category-web-development"],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"authors":[{"term_id":507,"user_id":15,"is_guest":0,"slug":"eoin","display_name":"Eoin Malins","avatar_url":"https:\/\/secure.gravatar.com\/avatar\/e91a9cf8b77625a1bc34e56f5dc36439a1f61476804b087e5b47554425879210?s=96&d=mm&r=g","0":null,"1":"","2":"","3":"","4":"","5":"","6":"","7":"","8":""}],"_links":{"self":[{"href":"https:\/\/www.blopig.com\/blog\/wp-json\/wp\/v2\/posts\/7282","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.blopig.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.blopig.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.blopig.com\/blog\/wp-json\/wp\/v2\/users\/15"}],"replies":[{"embeddable":true,"href":"https:\/\/www.blopig.com\/blog\/wp-json\/wp\/v2\/comments?post=7282"}],"version-history":[{"count":5,"href":"https:\/\/www.blopig.com\/blog\/wp-json\/wp\/v2\/posts\/7282\/revisions"}],"predecessor-version":[{"id":7319,"href":"https:\/\/www.blopig.com\/blog\/wp-json\/wp\/v2\/posts\/7282\/revisions\/7319"}],"wp:attachment":[{"href":"https:\/\/www.blopig.com\/blog\/wp-json\/wp\/v2\/media?parent=7282"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.blopig.com\/blog\/wp-json\/wp\/v2\/categories?post=7282"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.blopig.com\/blog\/wp-json\/wp\/v2\/tags?post=7282"},{"taxonomy":"author","embeddable":true,"href":"https:\/\/www.blopig.com\/blog\/wp-json\/wp\/v2\/ppma_author?post=7282"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}