Fix Python – Case Insensitive Flask-SQLAlchemy Query

I’m using Flask-SQLAlchemy to query from a database of users; however, while
user = models.User.query.filter_by(username=”ganye”).first()

will return

doing
user = models.User.query.filter_by(username=”GANYE”).first()

returns
None

I’m wondering if there’s a way to query the database in a case insensitive way, so that the second ….

Fix Python – Case insensitive regular expression without re.compile?

In Python, I can compile a regular expression to be case-insensitive using re.compile:
>>> s = ‘TeSt’
>>> casesensitive = re.compile(‘test’)
>>> ignorecase = re.compile(‘test’, re.IGNORECASE)
>>>
>>> print casesensitive.match(s)
None
>>> print ignorecase.match(s)
<_sre.SRE_Match object at 0x02F0B608>

Is there a way to do the same, but without us….