from datetime import datetime


def start_of_month(dt, d_years=0, d_months=0):
    """
    Given a date, return a date first day of the month.
    
    @param dt: The date to base the return value upon.
    @param d_years: Specify a delta in years to apply to date.
    @param d_months: Specify a delta in months to apply to date.
    
    @see http://code.activestate.com/recipes/476197-first-last-day-of-the-month/
    """
    y, m = dt.year + d_years, dt.month + d_months
    a, m = divmod(m-1, 12)
    return datetime(y+a, m+1, 1)