ποΈ Build a Portfolio & GitHub Profile
in Python
Build a Python portfolio on GitHub: choose projects, write a README, learn git basics, .gitignore, licences, project structure, GitHub Pages and good commit habits.
What this lesson is about
A portfolio is evidence of what you can do. Anyone can write that they know Python; a repository that anyone can open, read, install and run shows it. For a learner, a freelancer or someone changing field, a handful of well-presented projects on GitHub is the most direct way to let other people judge your work for themselves instead of taking your word for it.
Most of what makes a repository look finished is not clever code. It is a clear README, a sensible folder layout, a .gitignore so no junk is committed, a licence, commit messages a stranger can follow and a short explanation of why you made the choices you did. These are habits, and every one of them can be learned in an afternoon and applied to each project you build.
This lesson walks through choosing projects, structuring the README, the git commands you need day to day, ignoring files, picking a licence, laying out a project, publishing with GitHub Pages and a profile README, keeping tidy commits and writing about decisions. The runnable examples are small tools you can use on your own work: a README checklist scorer, a commit message validator built with re, and a project-structure printer. I make no promises about jobs or outcomes; the goal is to make your work easy to understand and easy to trust. For project ideas, see project ideas.
What you will learn
- βChoose a small set of projects that show different skills
- βStructure a README so a visitor understands the project in a minute
- βUse the everyday git commands: init, status, add, commit, branch, push
- βWrite a correct
.gitignoreand keep secrets out of history - βChoose a licence and understand what having none means
- βLay out a Python project with source, tests and configuration
- βPublish a page with GitHub Pages and write a profile README
- βWrite consistent commit messages and short notes about your decisions
Why programmers should learn this
- β Reviewers rarely have time to read all your code, so a clear README and tidy history let them judge the work quickly and fairly.
- β Version control is a daily tool in almost every software team; practising it on your own projects is practice for real collaboration.
- β A project with tests, a licence and setup instructions shows you finish things, which is often more telling than how big the project is.
- β Writing down why you chose a design makes you think harder about it and gives you something concrete to discuss when anyone asks about your work.
- β Good habits such as ignoring secrets and keeping commits small prevent real mistakes, like publishing an API key by accident.
Choosing what goes in your portfolio
Three to five projects that are finished and explained beat twenty abandoned experiments. I choose projects to show different things: one that handles data from input to output, one that talks to an outside service or file format, one with a user interface or command-line interface, and one with real tests. A tutorial clone is fine for learning, but for the portfolio pick problems you adapted or invented so the decisions are yours.
Scope matters more than ambition. A tool that does one job well, has instructions anyone can follow and handles bad input gracefully shows more skill than a half-working large idea. If you need inspiration, project ideas lists many starting points that you can shrink to a weekend size.
Pin your best repositories on your GitHub profile, archive or delete the ones you would not want a stranger to read, and make sure the code in each repository really runs from a fresh clone. Test that last point yourself in a new folder and virtual environment; it is the commonest way a good project looks broken.
Project Shows Input -> Output Tests? README done? ------------- --------------- ------------------------ ------ ------------ expense-cli CLI, files CSV -> summary report yes yes weather-bot HTTP, JSON API -> daily message some yes note-search text, sqlite notes -> search results yes no
Line by line
- 1-2Column headings: what the project demonstrates and what flows in and out of it.
- 3-5Fill one row per project. A blank 'Tests?' or 'README done?' tells you what to improve before you share it.
Finish and polish before you start the next project. A short list of complete work is a stronger signal than a long list of unfinished repositories.
A README that explains your project in a minute
The README is the front page of your repository, written in Markdown. A visitor decides within seconds whether to keep reading, so lead with what the project does in one or two sentences, then show it: a screenshot, a short output sample or a usage example. Only after that come installation steps, configuration, how to run the tests and a short note on what you would do next.
I use a consistent order: title and one-line summary, a demo or example, features, installation, usage, how it works or design notes, tests, licence. Each installation instruction should be copy-pasteable and tested on a clean machine. State the Python version and list the dependencies in requirements.txt or pyproject.toml so the reader does not have to guess.
Be honest about limits. A section titled 'Known limitations' makes you look careful, not weak, and it prevents a reader from misusing the project. Avoid claims you cannot show, such as 'fast' or 'production ready', and prefer a measurable statement: what input it accepts, what it outputs, how it was tested.
# expense-cli
Summarise a CSV of expenses by category from the command line.
## Demo
$ python -m expense_cli data/sample.csv
food 123.40
transport 45.00
## Features
- Reads CSV files with date, category and amount columns
- Prints totals per category, largest first
## Installation
python -m venv .venv
source .venv/bin/activate
pip install -r requirements.txt
## Usage
python -m expense_cli path/to/file.csv
## How it works
Short notes on the design and the trade-offs I made.
## Tests
pytest
## Known limitations
- Amounts must use a dot as the decimal separator
## Licence
MITLine by line
- 1-3The title and a one-sentence description tell a visitor immediately what this is.
- 5-9A demo block with real output: showing the result is more convincing than describing it.
- 11-13Bullet the features rather than writing a paragraph.
- 15-18Installation uses a virtual environment and a requirements file so the steps work on a clean machine.
- 20-21One command that shows how to run it.
- 23-24Space for design notes; this is where you explain decisions.
- 26-27Tell readers how to run the tests.
- 29-30Be upfront about limitations.
- 32-33State the licence.
Check your README with a small scorer
Checklists are most useful when a program applies them. The scorer below looks at the text of a README and checks for the sections described in the last lesson: a title, a description, an installation heading, a usage heading, a tests heading, a licence heading and at least one code block. It is deliberately simple, because the goal is a reminder you can run on every project, not a perfect judge of quality.
The code uses re.search with re.IGNORECASE | re.MULTILINE so that ## Installation, ## installation and ### Install can all match. Each check is a name paired with a pattern, kept in a list so adding a rule is one line. The score is the share of checks that pass, and the function also returns the missing items so you know what to write next.
Treat the number as a prompt, not a grade. A README can contain every heading and still be unhelpful, and a short one can be perfect for a tiny script. What the tool is good at is catching things you forgot, such as the licence line or the test instructions.
import re
CHECKS = [
("title", r"^#\s+\S"),
("description", r"^#\s+.+\n+\S"),
("installation", r"^#{2,3}\s+install"),
("usage", r"^#{2,3}\s+usage"),
("tests", r"^#{2,3}\s+tests?"),
("licence", r"^#{2,3}\s+licen[cs]e"),
("code example", r"^( {4}|\t)\S|```"),
]
def score_readme(text):
flags = re.IGNORECASE | re.MULTILINE
passed = [name for name, pattern in CHECKS if re.search(pattern, text, flags)]
missing = [name for name, _ in CHECKS if name not in passed]
return round(100 * len(passed) / len(CHECKS)), missing
good = """# demo-tool
Counts words in a file.
## Installation
pip install -r requirements.txt
## Usage
python count.py notes.txt
## Tests
pytest
## Licence
MIT
"""
weak = "# demo-tool\nSome script."
for label, text in [("good", good), ("weak", weak)]:
score, missing = score_readme(text)
print(label, score, "missing:", missing)good 100 missing: [] weak 29 missing: ['installation', 'usage', 'tests', 'licence', 'code example']
Line by line
- 1
reis the standard regular-expression module. - 3-11A list of (name, pattern) pairs. Each pattern looks for a heading line or an indented code block.
- 13-17Run each pattern against the text, collect what passed and what did not, and return a percentage score and the missing names.
- 19-33A complete README and a sketchy one, as test inputs.
- 35-37Score both and print the result with the missing items.
The weak example passes the title and description checks but is missing installation, usage, tests, licence and any code example. That mirrors a common README problem: a one-line blurb with nothing a visitor can act on.
Git basics you will use every day
Git records snapshots of your project called commits. You stage the changes you want with git add, record them with git commit -m, look at the state with git status and at history with git log --oneline. Between your computer and GitHub sits a remote, usually called origin; git push sends your commits there and git pull brings others' changes back.
Branches let you try something without disturbing the main line. git switch -c feature-name creates and moves to a new branch, and after you finish you merge it back, directly or through a pull request on GitHub. Even on a solo project, working on a branch and merging keeps main always in a working state, and it teaches the workflow that teams use.
Learn two safety commands early. git diff shows exactly what you are about to commit, which catches debugging leftovers; and git restore <file> throws away uncommitted changes to a file, which is permanent, so look before you run it. If you have already pushed a mistake, prefer a new commit that fixes it over rewriting shared history.
git init git status git add README.md main.py git commit -m "Add word counter with README" git branch -M main git remote add origin https://github.com/YOUR-NAME/word-counter.git git push -u origin main git switch -c add-tests git add tests/ git commit -m "Add tests for empty and unicode input" git switch main git merge add-tests git log --oneline
Line by line
- 1Turn the current folder into a git repository.
- 2See which files are new, changed or staged.
- 3-4Stage two files, then record them as a commit with a message.
- 5Make sure the main branch is called
main. - 6-7Connect the folder to an empty GitHub repository you created, and push the first time with
-uso later pushes need no arguments. - 9-11Create a branch for a new piece of work, stage the tests and commit them.
- 12-13Return to
mainand merge the finished branch. - 14Show a compact history, one line per commit.
.gitignore, secrets and licences
A .gitignore file lists patterns of files git should not track. In a Python project that means virtual environments (.venv/), bytecode caches (__pycache__/), build output, editor settings and local data. Create it before your first commit: files that are already tracked stay tracked even if you add them to .gitignore later, and you would have to remove them with git rm --cached.
The most important rule is never to commit secrets: API keys, passwords, tokens and .env files. Git history is permanent, so deleting the file in a later commit does not remove it from earlier ones, and anyone can view it. Keep secrets in environment variables, commit an .env.example with placeholder values and, if a real key ever leaks, revoke it at the provider immediately; cleaning history is only a secondary step.
Licences tell others what they may do with your code. Without one, the default in most places is that nobody else has permission to use, copy or change it, even though it is visible. Common choices are MIT and BSD, which are very permissive, Apache-2.0, which permissive with an explicit patent grant, and GPL, which requires derivative works to stay open under the same terms. Pick the one that matches what you want, add a LICENSE file and mention it in the README. For a legal question about your own situation, ask a qualified person.
# environments and secrets .venv/ venv/ .env # python caches and build output __pycache__/ *.pyc .pytest_cache/ dist/ build/ *.egg-info/ # editors and operating system .vscode/ .idea/ .DS_Store # local data data/private/ *.sqlite3
Line by line
- 1-4Virtual environments are large and machine-specific;
.envoften holds secrets. - 6-11Generated files that can always be recreated.
- 13-16Personal editor settings and system files.
- 18-20Local data you do not want to publish, such as private datasets and databases.
If you ever commit a real key, treat it as public: revoke it and create a new one before doing anything else.
Project structure that looks professional
A predictable layout lets a stranger find things without asking. The shape I recommend for a small application is a top-level folder with README.md, LICENSE, .gitignore, pyproject.toml or requirements.txt, a package folder holding the code, and a tests folder beside it. Put runnable entry points in a __main__.py or a small cli.py so the project can be started with python -m package_name.
A src/ layout, where the package sits inside src/, avoids accidentally importing from the working directory and is a good habit for anything you may publish; a flat layout is fine for small projects. Either way, keep modules small and named by what they do (parser.py, report.py), keep data samples in a data/ folder and keep documentation next to the code. See packaging for how this grows into an installable package.
The tool below prints a tree from a list of paths using only the standard library, which is handy for README 'Project layout' sections and for checking your own structure. It sorts entries so output is stable, puts folders before files, and draws the familiar branch characters.
def build_tree(paths):
tree = {}
for path in paths:
node = tree
for part in path.strip("/").split("/"):
node = node.setdefault(part, {})
return tree
def render(node, prefix=""):
lines = []
entries = sorted(node.items(), key=lambda kv: (not kv[1], kv[0]))
for i, (name, child) in enumerate(entries):
last = i == len(entries) - 1
lines.append(prefix + ("βββ " if last else "βββ ") + name + ("/" if child else ""))
if child:
lines.extend(render(child, prefix + (" " if last else "β ")))
return lines
files = [
"README.md", "LICENSE", ".gitignore", "pyproject.toml",
"expense_cli/__init__.py", "expense_cli/__main__.py",
"expense_cli/reader.py", "expense_cli/report.py",
"tests/test_reader.py", "tests/test_report.py",
"data/sample.csv",
]
print("expense-cli/")
print("\n".join(render(build_tree(files))))expense-cli/ βββ data/ β βββ sample.csv βββ expense_cli/ β βββ __init__.py β βββ __main__.py β βββ reader.py β βββ report.py βββ tests/ β βββ test_reader.py β βββ test_report.py βββ .gitignore βββ LICENSE βββ README.md βββ pyproject.toml
Line by line
- 1-7Turn slash-separated paths into nested dictionaries: each folder is a key whose value holds its children.
- 9-12For one level, sort so folders (non-empty dictionaries) come first, then alphabetical.
- 13-16Choose the branch symbol, add a trailing slash to folders, and recurse with an adjusted prefix so the vertical lines continue correctly.
- 19-26A sample project as a flat list of paths.
- 28-29Print the root folder name and then the rendered tree.
GitHub Pages, profile README and commit habits
GitHub Pages serves static files from a repository for free, which is ideal for a project demo or a small portfolio site made of HTML, CSS and JavaScript. In the repository settings you choose which branch (and folder) to publish, and a few minutes later the site is live at a github.io address. Python itself does not run on Pages, so use it for documentation, a generated report or a front end, and keep server code somewhere else.
Your profile README is a repository named exactly like your username, with a README.md in it; GitHub shows that file at the top of your profile. Keep it short: who you are, what you are learning or working on, links to your two or three best projects and a way to contact you. Resist badge walls and animated widgets that distract from the work.
Commit habits do more for your image than any badge. Make small commits that each do one thing, write the subject in the imperative mood (Add CSV export, not added stuff), keep it under about 50 to 72 characters, and add a body when the reason is not obvious. A common convention is a type prefix such as feat:, fix:, docs:, test: and refactor:. The validator below enforces a simple version so you can see how a rule becomes code.
import re
PATTERN = re.compile(
r"^(feat|fix|docs|test|refactor|chore)" # type
r"(\([a-z0-9_-]+\))?" # optional scope
r": "
r"(?P<subject>\S.*)$"
)
def check_commit(message):
problems = []
subject = message.splitlines()[0] if message.strip() else ""
match = PATTERN.match(subject)
if not match:
problems.append("use 'type: subject' (feat, fix, docs, test, refactor, chore)")
else:
text = match.group("subject")
if len(subject) > 72:
problems.append("subject longer than 72 characters")
if text.endswith("."):
problems.append("no full stop at the end of the subject")
if text[0].isupper():
problems.append("start the subject in lower case")
return problems
messages = [
"feat(report): add CSV export",
"fixed stuff",
"docs: Update the README.",
"test: cover empty input",
"",
]
for m in messages:
issues = check_commit(m)
print(repr(m), "->", "ok" if not issues else issues)'feat(report): add CSV export' -> ok 'fixed stuff' -> ["use 'type: subject' (feat, fix, docs, test, refactor, chore)"] 'docs: Update the README.' -> ['no full stop at the end of the subject', 'start the subject in lower case'] 'test: cover empty input' -> ok '' -> ["use 'type: subject' (feat, fix, docs, test, refactor, chore)"]
Line by line
- 3-8A compiled pattern: a type word, an optional scope in brackets, a colon and a space, then a non-empty subject captured under the name
subject. - 10-12Look only at the first line of the message; an empty message gives an empty subject.
- 13-15No match means the message does not follow the format.
- 16-23If it matches, add checks for length, a trailing full stop and an upper-case first letter.
- 26-32Five sample messages, good and bad.
- 34-36Print the problems found for each message.
Tools such as commit hooks can run a check like this automatically before each commit. For the longer story, add short 'decision notes' to your README or a docs/decisions.md file: one paragraph on each significant choice, what else you considered and why you chose this option. That writing is often the part readers remember.
Common mistakes
β Committing secrets or large junk files
API keys, .env files, virtual environments and datasets do not belong in the repository. Add a .gitignore before the first commit, keep secrets in environment variables and revoke anything that leaked.
β A repository with no README
Visitors will not read code to find out what a project does. Start with a one-line description, a demo and installation steps that you have tested on a clean machine.
β Giant commits with vague messages
Messages like update or fix stuff and commits that change twenty things make history useless. Commit one logical change at a time with an imperative, descriptive subject.
β Publishing code with no licence
Without a licence, others generally have no permission to reuse your work. Add a LICENSE file that matches your intention, and mention it in the README.
β Showcasing projects that do not run
If installation fails on a fresh clone, the project looks abandoned. Test in a new virtual environment, list dependencies and fix the steps until they work.
Quick quiz
Tap an answer. I explain every one, right or wrong.
Q1. Which command records staged changes as a commit?
git commit saves the staged snapshot; add stages, push uploads and status only reports.Q2. You added .env to .gitignore after committing it. What is true?
.gitignore only affects untracked files; tracked files stay tracked, and history keeps old content.Q3. What is the effect of having no licence on public code?
Q4. Which repository name creates your GitHub profile README?
Q5. What belongs first in a README?
Q6. Which is the best commit subject?
Frequently asked questions
How many projects should a portfolio have?
+Quality matters more than count. Three to five complete, documented projects that show different skills are plenty. Retire or archive anything you would not want a reader to judge you by.
Can I use tutorial projects in my portfolio?
+You can include them if you clearly say so and add something of your own, such as a new feature, tests or a different data source. Projects with your own decisions are more convincing.
Should I choose MIT or GPL?
+MIT is permissive and simple: others can reuse the code with few conditions. GPL requires derivative works to be shared under the same licence. Choose based on what you want others to be able to do, and read the licence text or ask a qualified person if the stakes are high.
Do I need GitHub Pages?
+No. It is useful for a demo site or documentation made of static files, but a good README is enough for most Python projects. Python code cannot run on Pages; it only serves static content.
What if my commit history is messy already?
+Do not rewrite shared history for appearance. Start good habits from now on, write a clear README and use small commits and branches in the next projects. For a private, unpushed branch you can tidy commits before sharing.
Key takeaways
- βChoose a few finished projects that show different skills, and make sure each one runs from a fresh clone.
- βWrite a README with a one-line purpose, a demo, tested installation steps, usage, tests, limitations and a licence.
- βLearn the daily git loop (
status,add,commit,push) and use branches to keepmainworking. - βAdd
.gitignorebefore the first commit and never commit secrets; revoke any key that leaks. - βAdd a
LICENSE, a predictable folder layout and decision notes explaining why you built it that way. - βKeep commits small with clear, consistent messages, and use GitHub Pages and a short profile README only to present real work.