You have that project that inspires you, and have started learning a little Python and seeking more resources, and now you’re probably thinking “but how do I do [thing I specifically need]?”
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.
![hamster robot that you can program with python](https://digitalfellows.commons.gc.cuny.edu/wp-content/blogs.dir/1120/files/2017/12/new_pet.png)
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:
import soul
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?
- Beautiful Soup – Web scraper designed for quick turnaround projects like screen-scraping.
- Scrapy – Framework for extracting the data you need from websites. In a fast, simple, yet extensible way.
work with..
- spreadsheets and tables?
- Pandas – Python Data Analysis Library
- arrays and matrices?
- shapefiles and geographic data?
- images and video?
- audio?
- librosa – Library for audio and music analysis
- Parselmouth – Praat in Python, the Pythonic way
- databases?
- 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?
- scikit-learn – Tools for data mining and data analysis
- keras – Deep Learning Library
- PyTorch – Tensors and Dynamic neural networks
- network analysis?
- NetworkX – Software for complex networks
visualize data….
- in publish worthy plots?
- matplotlib – Static and interactive data visualization
- seaborn – Statistical data visualization
- in interactive dashboards?
- on a map?
- cartopy – Cartographic tools
- basemap – Extends matplotlib to allow plotting 2D data on maps
test code?
- pytest – write clean unit and functional tests
- hypothesis – a modern implementation of property based testing
- 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?
- Check out our Digital Resource Guide & Resources
- Come to PUG, Consultations, DSL Open House, Workshops, Skill Shares and our other events
- Tweet @Digital_Fellows and Contact Us
- Join https://commons.gc.cuny.edu/groups/gcdi/