How To Package A Game of Tic-Tac-Toe and Upload It To PyPI

A growing trend I’ve been noticing in Data Science is the rise of MLOps. MLOps encompasses the set of emerging best practices for taking an experimental Machine Learning model into a production web system.
Experimentation is great, but there comes a time when you really want to build something tangible that others can benefit from – well at least I know that time has come for me. It’s for this reason, I’ve been sharpening up my Programming and software engineering skills, as these skills play a vital role in taking experimental Machine Learning projects into production.
Data Scientists Should Know Software Engineering Best Practices
Motivation
Readers of my articles, especially those that read The Moment I Realized Data Science Certificates Won’t Push My Career Forward, would know I prefer a hands-on approach when it comes to developing new skills. Therefore, I took it upon myself to develop a fun Tic-Tac-Toe project to acquaint myself with object-oriented programming (OOP) with Python, then I packaged the project and uploaded it to PyPI – Yes, that means you can literally pip install my project.
Step 1 – Adding Structure
Unlike the experiments we Data Scientists are accustomed to in our Jupyter Notebook, software engineering projects are very well structured right off the bat, since there’s already a clear end-goal with what they are trying to accomplish – something that could only be known after lots of experiments in Data Science.
In Machine Learning projects, the actual code that is written makes up only a small fraction of the Machine Learning system, hence it’s reasonable to consider a Machine Learning Project at scale as a Software project. Therefore, taking the time to structure Machine Learning projects pays dividends in the long run, and what better way to gain experience than by creating a real software project?
board_game/
├── LICENSE
├── pyproject.toml
├── README.md
├── setup.cfg
├── setup.py # optional, needed to make editable pip installs work
├── tic_tac_toe/
│ └── __init__.py/
│ └── board.py
└── tests/
Breaking down the Files/Folders
The code cell above details the structure of the project, but here is what each file means:
LICENSE
: This tells users who install your package the terms under which they can use your package. For help picking a license, see https://choosealicense.com/.pyproject.toml
: A file that informs build tools, likepip
andbuild
, the systems being used and what is necessary for building. If this file does not exist in your projects, the classic setuptools build system will be assumed, but it’s always good to be explicit.README.md
: AREADME.md
informs others how to navigate your project. Read How To Make Your Data Science Projects Stand Out.setup.cfg
:setup.cfg
is static metadata that informs setuptools about the package you’re creating (i.e. the name of the package, the version, etc.) and which code files ought to be included.setup.py
:setup.py
is dynamic metadata and serves as the build script for setuptools. In truth, since I usedsetup.cfg
I didn’t need to includesetup.py
– The documentation goes further in-depth as to why this is.tic_tac_toe/
: This the directory we keep our source code in.board_game/tic_tac_toe/__init__.py
is required to import the directory as a package, and should be empty.tests/
: This directory is a placeholder for test files. I haven’t currently written any tests, but I do plan to in the future – Advocates for Test Driven Development (TDD) destroy me for this and I think software engineers, in general, will too. Testing is vital as it discovers defects/bugs before the delivery to the client, which guarantees the quality of the software (you wouldn’t get on a ride that hasn’t be tested would you?).
Step 2 – Building the Application
Since I am already quite comfortable with programming, I didn’t want to waste too much time thinking about the program’s logic – remember, my main focus is to develop my OOP skills and gain experience packing projects which could then be uploaded to PyPI.
To escape the logic aspect of the project, I took code from Tic-Tac-Toe Game – Python Tkinter GUI Tutorial, but instead of taking the code as it is, I converted the script into a Python object.
What is a Class?
A class
defines the template for creating objects in Python – to help simplify the concept of an object, consider things in the real world such as a human, a car, etc. All objects have characteristics, which is referred to as an attribute, For instance, I am a human (object) but I have characteristics (attributes) that set me apart from other humans (i.e. I am 5’9, I have black hair, I am a freelancer, etc).
Aside from my attributes, I can also carry out actions that permit me to function effectively in the real world, these actions are known as methods. For example, I can exercise, read a book, watch Netflix, etc.
This is effectively what makes up an object in Python. To create an object in Python, we must call class
. Here’s the code I used to create my Tic Tac Toe object.
Note: In the future, I wish to return to this code to refactor and improve it therefore, I am extremely open to critique.
Step 3 – Generating Distribution Archives
To permit others to access our package when they do a pip install
, we must generate distribution packages for our package. I use a Windows operating system so that’s what I’ll be using to generate the package – Users of Unix/macOS operating systems should consult the PyPA Documentation.
The first part of the process is ensuring we have the most up-to-date version of PyPA’s build
installed. From the terminal, ensure you’re in the projects virtual environment and enter:
py -m install --upgrade build
Next, navigate to the directory that contains pyproject.toml
and enter:
py -m build
You’ll see a load of text in your terminal after running this command, but to ensure everything went smoothly, you can check if the directory you ran the command in has a dist/
directory with 2 files in it. Here’s how mine looks…

Step 4 – Uploading the package to PyPI test
Once this is done, we can now upload our package to the Python Package Index (PyPI).
In order to upload a package, you must be registered to PyPI‘s index – This is the easiest step you’ll ever have to carry out – use the following links to register to PyPI and TestPyPI respectively.
Note: PyPI test is a separate instance of PyPI. It is intended for testing and experimentation.
After registering, we can then upload the twine
package to aid us in uploading the distribution packages.
# installing twine
py -m pip install --upgrade twine
# uploading the archives under the dist directory
py -m twine upload --repository testpypi dist/*
Running the commands above from your terminal will prompt you to insert the username and password that you used to register for TestPyPI. When you have done so, your package should now be viewable on TestPyPI. Here’s mine…
Step 5 – Installing the Package
To verify our package works, it’s a good idea to use pip
to install it and test its functionality.
pip install -i https://test.pypi.org/simple/ board-game-kurtispykes==0.0.1
Next, go to a new terminal and enter py
and test the package by running the following commands:

The output should open a new window with the Tic Tac Toe game.
Final Thoughts
I’ve now uploaded the package to PyPI so you can simply install the package and test it out by running pip install board_game_kurtispykes
. Whilst I’m quite aware that this package is up to the standards of Scikit-Learn or NumPy, I’m very happy with the experience I’ve gained running through the procedure and look forward to revisiting the package at a later date to make improvements to my code, additional testing, and possibly more functionality (including more games) – I’m very open to critique because I know software engineering skills isn’t particularly my strength.
Thank You for Reading!
If you enjoyed this article, connect with me by subscribing ** to my FRE**E weekly newsletter. Never miss a post I make about Artificial Intelligence, Data Science, and Freelancing.
Related Articles
3 Ways to Drastically Improve Your Programming Skills On Your Own