My implementation that you can use with SQLAlchemy and PostgreSQL:
def urlize(s, allow='_', disallow='/-'):
"""Returns a pretty, hyphenated string for search engine optimized URLs.
To use within PostgreSQL as a PL/Python function:
CREATE OR REPLACE FUNCTION urlize (s varchar)
I would like to properly encode spaces as hyphens in urls and I think
the following python functions perform the quoting/unquoting I'm
looking for:
def url_quote_hyphen(text): return
urllib.quote_plus(text).replace('-','%2D').replace('+','-')
def url_unquote_hyphen(text): return
urllib.unquote_p