aioorm.utils.csv_utils package

Submodules

aioorm.utils.csv_utils.csv_dump module

aioorm.utils.csv_utils.csv_dump.aiodump_csv(query, file_or_name, loop=None, include_header=True, close_file=False, append=True, csv_writer=<class 'aioorm.utils.csv_utils.csv_dump.csv_writer'>)[source]
class aioorm.utils.csv_utils.csv_dump.csv_writer(fh, fieldnames=None, delimiter=', ')[source]

Bases: object

writeheader(fieldnames=None)[source]
writerow(row)[source]

aioorm.utils.csv_utils.csv_loader module

class aioorm.utils.csv_utils.csv_loader.Get_Reader(file_or_name, **reader_kwargs)[source]

Bases: object

class aioorm.utils.csv_utils.csv_loader.Loader(db_or_model, file_or_name, fields=None, field_names=None, has_header=True, sample_size=10, converter=None, db_table=None, pk_in_csv=False, **reader_kwargs)[source]

Bases: aioorm.utils.csv_utils.csv_loader._CSVReader

Load the contents of a CSV file into a database and return a model class suitable for working with the CSV data. :param db_or_model: a peewee Database instance or a Model class. :param file_or_name: the filename of the CSV file or a file handle. :param list fields: A list of peewee Field() instances appropriate to

the values in the CSV file.
Parameters:
  • field_names (list) – A list of names to use for the fields.
  • has_header (bool) – Whether the first row of the CSV file is a header.
  • sample_size (int) – Number of rows to introspect if fields are not defined.
  • converter – A RowConverter instance to use.
  • db_table (str) – Name of table to store data in (if not specified, the table name will be derived from the CSV filename).
  • reader_kwargs – Arbitrary arguments to pass to the CSV reader.
analyze_csv()[source]
clean_field_name(s)[source]
get_converter()[source]
get_model_class(field_names, fields)[source]
load()[source]
class aioorm.utils.csv_utils.csv_loader.Reader(fh, delimiter=', ', **kws)[source]

Bases: object

class aioorm.utils.csv_utils.csv_loader.RowConverter(database, has_header=True, sample_size=10)[source]

Bases: aioorm.utils.csv_utils.csv_loader._CSVReader

Simple introspection utility to convert a CSV file into a list of headers and column types. :param database: a peewee Database object. :param bool has_header: whether the first row of CSV is a header row. :param int sample_size: number of rows to introspect

analyze(rows)[source]

Analyze the given rows and try to determine the type of value stored. :param list rows: A list-of-lists containing one or more rows from a

csv file.
Returns:A list of peewee Field objects for each column in the CSV.
date_formats = ['%Y-%m-%d', '%m/%d/%Y']
datetime_formats = ['%Y-%m-%d %H:%M:%S', '%Y-%m-%d %H:%M:%S.%f']
default(value)[source]
extract_rows(file_or_name, **reader_kwargs)[source]

Extract self.sample_size rows from the CSV file and analyze their data-types. :param str file_or_name: A string filename or a file handle. :param reader_kwargs: Arbitrary parameters to pass to the CSV reader. :returns: A 2-tuple containing a list of headers and list of rows

read from the CSV file.
get_checks()[source]

Return a list of functions to use when testing values.

is_date(value)[source]
is_datetime(value)[source]
is_float(value)[source]
is_integer(value)[source]
matches_date(value, formats)[source]
aioorm.utils.csv_utils.csv_loader.aioload_csv(db_or_model, file_or_name, fields=None, field_names=None, has_header=True, sample_size=10, converter=None, db_table=None, pk_in_csv=False, **reader_kwargs)[source]

Load the contents of a CSV file into a database and return a model class suitable for working with the CSV data. :param db_or_model: a peewee Database instance or a Model class. :param file_or_name: the filename of the CSV file or a file handle. :param list fields: A list of peewee Field() instances appropriate to

the values in the CSV file.
Parameters:
  • field_names (list) – A list of names to use for the fields.
  • has_header (bool) – Whether the first row of the CSV file is a header.
  • sample_size (int) – Number of rows to introspect if fields are not defined.
  • converter – A RowConverter instance to use.
  • db_table (str) – Name of table to store data in (if not specified, the table name will be derived from the CSV filename).
  • reader_kwargs – Arbitrary arguments to pass to the CSV reader.
aioorm.utils.csv_utils.csv_loader.convert_field(field_class, **field_kwargs)[source]

Module contents