Set up a project directory
Last updated on 2025-08-25 | Edit this page
Overview
Questions
- How should we structure our project ?
- What is init.py ?
- How should be name our packages ?
Objectives
- To understand how to structure your project to be able to package it well.
- Understand the importance of init.py and where to place it.
- Giving unique but understandable names to our packages.
Introduction
It is important to structure your project properly and include the necessary files, while giving unique yet understandable package names.
Packages are a way to organize modules in a Python project. A project can contain several modules, and grouping them into packages helps keep the code organized and maintainable.
Every package should have a special file called init.py in its folder. The presence of this file signals to Python that the folder is a package, allowing it to be imported later in your code.
Project Structure
A typical project would look like :
└── my_package/
├── __init__.py
├── happy.py
└── sad.py
Lets create the same structure for our project in the codespace.
OUTPUT
✔ Created ...greet_me/pixi.toml
This create a following structure for us.
Please note, if you want to use a pyproject.toml
, you
need to use the syntax mentioned below. This is also our preferance and
we will use this file in the next lesson.
pixi.toml
: Lets view and edit the pixi.toml file
generated for us.
TOML
[workspace]
authors = ["Priyanka O"]
channels = ["conda-forge"]
name = "greet_me"
version = "0.1.0"
platforms = ["linux-64"]
description = "A simple greeting package."
[dependencies]
python = ">=3.10"
[tasks]
Lets go inside the project directory:
To add libraries via pixi command use this syntax :
OUTPUT
✔ Added requests >=2.32.5,<3
Let us see that gets added to the pixi.toml
You can also generate/ update pixi.lock
file via this
command :
OUTPUT
✔ Lock-file was already up-to-date
Alternatively, Lets install the dependencies now, which wiil generate
the pixi.lock
file. This is also useful when you clone
someone else repo, the dependencies are installed via the
pixi.lock
file
OUTPUT
✔ The default environment has been installed.
There is also a command to update your dependencies to newer versions where possible with latest compatible versions.
OUTPUT
▪ solving [━━━━━━━━━━━━━━━━━━━━] 0/1
▪ updating lock-files [━━━━━━━━━━━━━━━━━━━━] 0/2
OUTPUT
✔ Lock-file was already up-to-date
Let us now create a folder named my_package
and add 3
files inside it namely happy.py
, sad.py
and
__init__.py
Ultimately, our project structure should look like this :
greet_me/
├── LICENSE
├── pyproject.toml
├── README.md
├── pixi.toml
├── pixi.lock # auto-generated, do not edit
├── tests/
│ └── test_greetings.py
└── my_package/
├── __init__.py
├── happy.py
└── sad.py
Add the following task to the pixi.toml file and then run via pixi
OUTPUT
Yay! happy day! 😀
- Follow the folder structure
- dont forget to add the init.py file.
- Sequence of pixi commands : init -> add -> run -> lock ->install -> update