Skip to Main Content

Python

Python is a versatile programming language with a broad range of applications. Created by Guido van Rossum in the late 1980s, it is used in many domains, such as data science, machine learning, automation, and the development of games and web applications. As a result, it’s one of the world's most widely used programming languages.

At TXI, we reach for Python when we want to provide a conduit between machine learning models and the users they serve, using frameworks like Flask or FastAPI to provide APIs that our user interfaces can leverage. In addition, Python does a great job of leaning on native extensions for speed and efficiency while providing an excellent developer experience due to its readability and flexibility.

Python has become a go-to language for data science, machine learning, and artificial intelligence. This, coupled with excellent software engineering and web development support, makes it an ideal choice for building Data-Powered Products.

Python

What is Python?

Python is a high-level, general-purpose programming language focused on readability and extensibility. It is a cross-platform language, meaning the same code can be used on different operating systems, such as Windows, Mac, and Linux. In addition, its user-friendly syntax and ease of use mean that many people can quickly pick up and learn the language.

Python is an interpreted language, which means Python programs do not need to be compiled before they can be executed. This makes them quick and easy to debug while developing. One of the downsides of interpreted languages is that they can be slow compared to compiled languages like C or C++. However, when Python needs to be fast, it can call native C or C++ extensions that provide the required speed, allowing Python to act as a more user-friendly, declarative, domain-specific language on top.

Python is a dynamically-typed language, meaning programmers do not need to declare the types of objects explicitly. Instead, the type of each object is determined implicitly at runtime from its contents. Programs written in this manner can be introspected and modified at runtime using a practice called metaprogramming, increasing their suitability as domain-specific languages.

Python is a multi-paradigm language, as comfortable as a procedural scripting language, as it is a full-featured object-oriented language. In addition, it supports map-reduce style functional programming and offers other functional language features like generators and list comprehensions. With libraries such as NumPy, it even takes on a more declarative programming style, pushing the implementation decisions down to native extensions written in C or C++.

Python is popular in many domains, from academia to large corporations such as Google, Dropbox, and Instagram. It grew in popularity during the Open Source and Internet of Things boom, becoming one of the main languages of choice on Single Board Computers, such as the Raspberry Pi. For this reason, Python is often the first programming language people learn.

In recent years, it has seen a surge in popularity in Data Science and Artificial Intelligence, becoming ubiquitous in this space. Libraries such as NumPy, Pandas, SciKit, and PyTorch sit alongside tools like Jupyter Notebooks to lower the entry barrier while offering powerful features that benefit statistical analysis and machine learning.

Until 2018, Python's creator Guido van Rossum was considered the Benevolent Dictator For Life (BDFL) and had the final say on all language decisions. However, the Python Software Foundation now owns the language. The language has an open proposal system, known as Python Enhancement Proposals (PEP), and a documented philosophy in The Zen of Python that guides the design and use of the language.

React Native

What is Python used for?

Python is a powerful, versatile language that can be used for a variety of tasks. It is ubiquitous within Data Science and Artificial Intelligence, common in the Internet of Things and Single Board Computer communities, and popular with tech startups due to web frameworks such as Django and Flask. In addition, as an interpreted language available on all major operating systems, it is an excellent choice as a scripting language. Finally, as a free and open-source language with a user-friendly syntax, Python is often used to teach programming and other related technical skills.

Python has many libraries designed for parsing, manipulating, and analyzing data. Libraries like NumPy and SciPy wrap lower-level, number-crunching native extensions to provide expert-level functionality that is easier to use. Pandas makes it easy to load, transform, and analyze data, leaning on NumPy to provide the raw power necessary for working with large datasets. Graphing and visualization libraries such as Plotly, Matplotlib, and Seabourne provide the means to visualize the outputs of the other libraries, with StreamLit making it easy to spin up a simple web interface to enable user interaction. Finally, Jupyter Notebooks are computational documents containing both text and runnable code. They can be generated using a bundled web application or certain code editors and are a powerful way to develop and share data analysis and machine learning work. These libraries and tools combine to deliver a robust Data Science and Artificial Intelligence workflow.

When developing web applications, the Django web framework is a mature, full-featured library inspired by Ruby on Rails that many tech startups leverage. It provides an opinionated framework, with a convention-over-configuration approach that can shortcut the need for upfront technical decision making in favor of getting working code in front of customers more quickly. Flask is a more flexible web framework that swaps the opinionated nature of Django for a more composable, API-focused approach. Both of these frameworks are popular for developing web applications and APIs alike. FastAPI has risen in popularity in recent years due to its focus on modern development practices and asynchronous-by-default approach.

When developing web applications, the Django web framework is a mature, full-featured library inspired by Ruby on Rails that many tech startups leverage. It provides an opinionated framework, with a convention-over-configuration approach that can shortcut the need for upfront technical decision making in favor of getting working code in front of customers more quickly. Flask is a more flexible web framework that swaps the opinionated nature of Django for a more composable, API-focused approach. Both of these frameworks are popular for developing web applications and APIs alike. FastAPI has risen in popularity in recent years due to its focus on modern development practices and asynchronous-by-default approach.

Python has also become popular in the Internet of Things (IoT) space. As a language, it is easy to learn, available on all major operating systems, and open source, making it an excellent choice when developing code to run on various devices for multiple use cases. People often get into IoT projects through hack events or community projects, so it's essential that the language used is easy to pick up and become productive with quickly. Python has a large community and an extensive catalog of packages and modules that can help speed up development or bring complex computing tools to developers with little formal education in computer science. Similarly to machine learning, data analysis tools such as NumPy and Pandas can be a great way to process data from IoT devices. When combined with web application frameworks like Flask and FastAPI, powerful dashboards can be created to monitor and share data from IoT devices.

Python

Demonstration

One of the areas in which Python shines is its ecosystem for working with data and AI. In the example below, we use the OpenAI Python package to run a Large Language Model called Da Vinci, part of the GPT 3.5 family, in order to generate some flavor text for a Dungeons & Dragons adventure.

We built this simple script within a Jupyter Notebook, an interactive Python environment that lets us embed running code within a text document. This not only allows us to document our process in plain English, but it also allows us to build up an example step by step, thus making it easier to follow along.

The code below is a simplified version of the code contained in the Google Colab workbook that just presents the final Python code. It is also available as a GitHub gist if you would like to take it for a spin yourself.

"""
" Simple D&D Flavor Text Generator
"""

import openai
import pprint

# Please sign up for an OpenAI account, generate an API key and paste it below
# https://platform.openai.com/docs/api-reference/authentication
openai.api_key = "ADD VALID OPENAI API KEY HERE"

# prompt user for a short adventure topic, i.e. goblin bandits
topic = input("Enter adventure topic: ")

# generate flavor text
response = openai.Completion.create(
    model="text-davinci-003",
    prompt=f"Topic: {topic}\nDungeons and dragons adventure:",
    temperature=0.8,
    max_tokens=100,
    top_p=1,
    frequency_penalty=0.5,
    presence_penalty=0,
)

# we use a pretty printer to make the output a bit easier to read
pp = pprint.PrettyPrinter(indent=2)
pp.pprint(response.choices[0].text)

This is just one simple example of the sort of power that Python has. With relatively little effort, we could expand this to include a web front end that would let us prompt the user on a web page and deliver the output there, too.

Python

FAQs

  • Who created Python?
  • What are some key features of Python?
  • What are the different versions of Python?
  • What are some popular frameworks and libraries in Python?
  • What is the difference between props and state in React?
  • How do I install Python?
  • What is PIP?
  • What is a virtual environment in Python?
  • What is a Python module?
  • What is a Python package?
Python

Terminology

Python: A high-level programming language that is easy to learn and widely used for various applications, such as web development, data analysis, artificial intelligence, and scientific computing.

Interpreter: A program that reads and executes Python code, line by line, and produces output.

IDE: Integrated Development Environment. A software application that provides a comprehensive environment for coding, debugging, and testing programs.

Module: A file that contains Python code, usually with functions, classes, or variables that can be imported and used in other Python programs.

Package: A collection of related Python modules that are organized in a directory structure and can be easily installed and used by other Python programs.

Function: A reusable block of code that performs a specific task and can be called by other parts of a program.

Class: A blueprint for creating objects that encapsulates data and methods for manipulating that data.

Object: An instance of a class that has its own data and can perform actions according to the methods defined in the class.

Variable: A named memory location that stores a value or reference to an object.

String: A sequence of characters, enclosed in single or double quotes, that represents text in Python.

List: A collection of values or objects, enclosed in square brackets and separated by commas.

Tuple: A collection of values or objects, enclosed in parentheses and separated by commas. Tuples are immutable, meaning their values cannot be changed after creation.

Dictionary: A collection of key-value pairs, enclosed in curly braces and separated by commas.

Loop: A control structure that repeats a block of code multiple times, either a fixed number of times or until a certain condition is met.

Conditional statement: A control structure that executes different code blocks based on whether a certain condition is true or false.

Case Studies

Using data to accelerate development of new pharmaceuticals

Let’s start a conversation

Let's shape your insights into experience-led data products together.