def fromCSV(csvfile,out=None,fieldnames=None,fmtparams=None,conv_func={},
    empty_to_None=[]):
    """Conversion from CSV to PyDbLite
    csvfile : name of the CSV file in the file system

    out : path for the new PyDbLite base in the file system

    fieldnames : list of field names. If set to None, the field names must
    be present in the first line of the CSV file
    
    fmtparams : the format parameters for the CSV file, as described in 
    the csv module of the standard distribution
    
    conv_func is a dictionary mapping a field name to the function used to
    convert the string read in the CSV to the appropriate Python type. For
    instance if field "age" must be converted to an integer :
    conv_func["age"] = int
    
    empty_to_None is a list of the fields such that when the value read in
    the CSV file is the empty string, the field value is set to None
    """
    import csv
    import time
    import datetime
    
    if out is None:
        out = os.path.splitext(csvfile)[0]+".pdl"
        
    if fieldnames is None:
        # read field names in the first line of CSV file
        reader = csv.reader(open(csvfile))
        fieldnames = reader.next()

    reader = csv.DictReader(open(csvfile),fieldnames,fmtparams)
    reader.next() # skip first line

    db = PyDbLite.Base(out)

    conv_func.update({"__id__":int})
    auto_id = not "__id__" in fieldnames
    fieldnames = [ f for f in fieldnames if not f in ("__id__") ]
    
    kw = {"mode":"override"}
    db.create(*fieldnames,**kw)
    print db.fields
    
    next_id = 0
    records = {}
    while True:
        try:
            record = reader.next()
        except StopIteration:
            break
        if auto_id:
            record["__id__"] = next_id
            next_id += 1
        # replace empty strings by None
        for field in empty_to_None:
            if not record[field]:
                record[field] = None
        # type conversion
        for field in conv_func:
            if not isinstance(conv_func[field],(tuple,list)):
                record[field] = conv_func[field](record[field])
            else:
                # date or datetime
                date_class,date_fmt = conv_func[field]
                if not record[field]:
                    record[field] = None
                else:
                    time_tuple = time.strptime(record[field],date_fmt)
                    if date_class is datetime.date:
                        time_tuple = time_tuple[:3]
                    record[field] = date_class(*time_tuple)
        records[record["__id__"]] = record
    db.records = records
    db.commit()
    print len(db)
    return db