---
title: Escaping Text for URLs in Python
date: 2024-11-28T08:58:24+00:00
draft: false
tags:
  - programming
  - python
---
Escaping text for is really easy in Python. In fact, I used it for this project.
Here's how to do it:
```python
from urllib.parse import quote

starting_text = "Test!"
escaped_text = quote(starting_text)
```

Initially, I thought that `urllib.parse.urlencode` should be used for this but I didn't read the documentation properly.
I realised that `urllib.parse.urlencode` is used for creating query strings from a dict, whereas `urllib.parse.quote` is actually used for escaping text.