That’s where libraries come in. Libraries get their name from the physical equivalent – just like the GC library provides books that can help a project along, programming libraries provide code encapsulated as functions and objects to carry out tasks common to the domain of the library.
In this comic, the pair has a new pet and they’d really like it to have a soul. They find a solution via the (fictional) Soul library, and so they want to use this library in the script they’re writing to control the robot. They are able to use this library because of the Python keyword import, which tells Python to please go get the (installed!) Python library that follows the import statement. The full Python statement to import the Soul library is:
They can program their new pet via the Python interface for ROS (Robot Operating System)
What about if your problem isn’t robots? The following is a highly biased sampling of common tasks that the Digital Fellows are asked about and isn’t remotely exhaustive. The library recommendations are also highly biased because when possible you should always opt for well maintained open source projects with large sustainable communities. So what if you want to…
create a […] using a web-framework?
- single task web application
- Bottle – Micro web-framework with no dependencies
- single task web application that other people will actually use
- Flask – More robust micro web-framework
- web application that has to do a lot of things
- Pyramid – The Start Small, Finish Big Stay Finished Framework
- content management system
- Django – Web Framework for Perfectionists With Deadlines
get data from…
- most government/open datasets?
- sodaPy – Socrata Open Data API (Applications Programming Interface – how you talk to the site via code)
- what if there’s no good library?
- Requests – HTTP for Humans. Talk to the internet without having to write raw URLs
- sites with no public API?
- spreadsheets and tables?
- Pandas – Python Data Analysis Library
- arrays and matrices?
- shapefiles and geographic data?
- images and video?
- SQLAlchemy – SQL Toolkit and Object Relational Mapper
- data that’s a little too big?
explore data using…
- the scientific ecosystem?
- textual analysis ?
- descriptive and inferential statistics?
- StatsModels – Statistics in Python
- machine learning?
- network analysis?
- NetworkX – Software for complex networks
- in publish worthy plots?
- in interactive dashboards?
- on a map?
- pytest – write clean unit and functional tests
- splinter – automate browser actions like interacting with site buttons
What if you need a library not listed here? Searching “[my problem] + Python” in a web browser will almost definitely yield code, but there are also indexes of code that has been packaged (which means turned into a library) that make the installation process much easier:
- If you’re using the Anaconda distribution of Python (which is the one the fellows recommend), you should use their indexes when possible because they’ve tested that the code should work with their version of Python. Their indexes are conda and conda-forge.
- If the package isn’t in the conda channels, or you’re not using anaconda, then you should look in PyPi (Python Package Index).
What resources are there to help you find the right libraries and learn how to use them?