 <p>Simply replace:</p> <pre><code> .filter_by(year=year) .filter_by(month=month) </code></pre> <p>with:</p> <pre><code>from sqlalchemy.sql.expression import func # ... .filter(func.year(Logs.timestamp) == year) .filter(func.month(Logs.timestamp) == month) </code></pre> <p>Read more on this in <a href="http://docs.sqlalchemy.org/en/rel_0_9/core/functions.html" rel="nofollow">SQL and Generic Functions</a> section of documentation.</p>