I don't think that there is any relationship between urlencode and urlsafe. The urlencode is used to built the url and add query parameters. The urlsafe_base64encode method substitutes - instead of + and _ instead of / in the standard Base64 alphabet. However, the result can still contain =.

In PHP we propose a similar approach, as there is not a standard method to accomplish that, to ensure compatibility between data encoded in PHP, and which have to be decoded using Python. The scheme is the same, we substitute - instead of + and _ instead of / in the standard Base64 alphabet. Again the result can still contain =.