Skip to content

3.2. Libraries

What are Python Libraries?

A Python library is a collection of pre-written code that provides specific functionality so you don’t have to write everything from scratch.

The Python ecoysytsem is so vast, there is usually several libraries for each use case you might have.


Examples

  • Pyodbc - Accessing data from SQL databases
  • Polars - Fast data processing and manipulation
  • Statsmodels - Predictive modelling with GLMs
  • Catboost - Generally the best performing GBM library
  • MLFlow - Managing modelling workflows
  • SHAP - Explaining machine learning models
  • Plotly/Dash - Interactive data visualisation and dashboards
  • Flask - Web Applications/model serving
  • GreatTables - Great looking tables
  • PyTorch - Matrix computation and optimisation frameworks
  • Pytest - Testing code

How to use Python Libraries

uv add {library name}

Once installed, these can be imported into our code.

import polars as pl

This then allows the prefix pl. before any functions or objects from the polars library. This is useful to prevent any ambiguity when two libraries contain the same function names.

data = pl.read_csv('./frequency_set.csv')

We can also import single modules from a libary:

from polars import 

Libraries tend to have extensive documentation with 'Getting started' guides showing some toy examples that can be adapted to you use case.