quiffen.core package

Submodules

quiffen.core.accounts module

quiffen.core.categories_classes module

quiffen.core.qif module

exception quiffen.core.qif.ParserException

Bases: Exception

class quiffen.core.qif.Qif(*, accounts: Dict[str, Account] = {}, categories: Dict[str, Category] = {}, classes: Dict[str, Class] = {}, securities: Dict[str, Security] = {}, **extra_data: Any)

Bases: BaseModel

The main class of the package. For parsing QIF files.

See the readme for usage examples.

Parameters
accountsdict, default=None

A dict of accounts in the form {‘Account Name’: account_object}.

categoriesdict, default=None

A dict of categories in the form {‘Category Name’: category_object}.

classesdict, default=None

A dict of classes in the form {‘Class Name’: class_object}.

Attributes
model_extra

Get extra fields set during validation.

model_fields_set

Returns the set of fields that have been explicitly set on this model instance.

Methods

add_account(new_account)

Add a new account to the Qif object

add_category(new_category)

Add a new category to the Qif object

add_class(new_class)

Add a new class to the Qif object

add_custom_field(line_code, attr, field_type)

Add a custom field to the class for parsing from a QIF.

add_security(new_security)

Add a new security to the Qif object

copy(*[, include, exclude, update, deep])

Returns a copy of the model.

from_string(string[, separator])

Create a class instance from a string.

model_construct([_fields_set])

Creates a new instance of the Model class with validated data.

model_copy(*[, update, deep])

Usage docs: https://docs.pydantic.dev/2.10/concepts/serialization/#model_copy

model_dump(*[, mode, include, exclude, ...])

Usage docs: https://docs.pydantic.dev/2.10/concepts/serialization/#modelmodel_dump

model_dump_json(*[, indent, include, ...])

Usage docs: https://docs.pydantic.dev/2.10/concepts/serialization/#modelmodel_dump_json

model_json_schema([by_alias, ref_template, ...])

Generates a JSON schema for a model class.

model_parametrized_name(params)

Compute the class name for parametrizations of generic classes.

model_post_init(context, /)

We need to both initialize private attributes and call the user-defined model_post_init method.

model_rebuild(*[, force, raise_errors, ...])

Try to rebuild the pydantic-core schema for the model.

model_validate(obj, *[, strict, ...])

Validate a pydantic model instance.

model_validate_json(json_data, *[, strict, ...])

Usage docs: https://docs.pydantic.dev/2.10/concepts/json/#json-parsing

model_validate_strings(obj, *[, strict, context])

Validate the given object with string data against the Pydantic model.

parse(path[, separator, day_first, encoding])

Return a class instance from a QIF file.

parse_string(data[, separator, day_first])

Return a class instance from a string containing QIF data.

remove_account(account_name)

Remove an account from this Qif object

remove_category(category_name[, keep_children])

Remove a category from this Qif object

remove_class(class_name)

Remove a class from this Qif object

remove_security(security_symbol)

Remove a security from this Qif object

to_csv([path, data_type, date_format, ...])

Convert part of the Qif object to a CSV file.

to_dataframe([data_type, ignore])

Convert part of the Qif object to a Pandas DataFrame.

to_dict([ignore])

Convert the class instance to a dict.

to_qif([path, date_format, encoding])

Convert the Qif object to a QIF file

Config

construct

dict

from_list

from_orm

json

parse_file

parse_obj

parse_raw

schema

schema_json

update_forward_refs

validate

accounts: Dict[str, Account]
add_account(new_account: Account) None

Add a new account to the Qif object

add_category(new_category: Category) None

Add a new category to the Qif object

add_class(new_class: Class) None

Add a new class to the Qif object

add_security(new_security: Security) None

Add a new security to the Qif object

categories: Dict[str, Category]
classes: Dict[str, Class]
classmethod from_list(lst: List[str]) Qif
model_config: ClassVar[ConfigDict] = {'extra': 'allow'}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

model_post_init(context: Any, /) None

We need to both initialize private attributes and call the user-defined model_post_init method.

classmethod parse(path: Union[Path, str], separator: str = '\n', day_first: bool = False, encoding: str = 'utf-8') Qif

Return a class instance from a QIF file.

Parameters
pathUnion[FilePath, str]

The path to the QIF file.

separator : str, default=’

The line separator for the QIF file. This probably won’t need changing.

day_firstbool, default=False

Whether the day or month comes first in the date.

encodingstr, default=’utf-8’

The encoding of the QIF file.

Returns
Qif

A Qif object containing all the data in the QIF file.

classmethod parse_string(data: str, separator: str = '\n', day_first: bool = False) Qif

Return a class instance from a string containing QIF data.

Parameters
datastr

The string of QIF data

separator : str, default=’

The line separator for the QIF file. This probably won’t need changing.

day_firstbool, default=False

Whether the day or month comes first in the date.

Returns
Qif

A Qif object containing all the data in the QIF file.

remove_account(account_name: str) Account

Remove an account from this Qif object

remove_category(category_name: str, keep_children: bool = True) Category

Remove a category from this Qif object

remove_class(class_name: str) Class

Remove a class from this Qif object

remove_security(security_symbol: str) Security

Remove a security from this Qif object

securities: Dict[str, Security]
to_csv(path: Optional[Union[Path, str]] = None, data_type: QifDataType = QifDataType.TRANSACTIONS, date_format: str = '%Y-%m-%d', ignore: Optional[List[str]] = None, delimiter: str = ',', quote_character: str = '"', encoding: str = 'utf-8') str

Convert part of the Qif object to a CSV file. The data_type parameter can be used to specify which part of the Qif object to convert to CSV. The default is to convert transactions.

Parameters
pathUnion[FilePath, str, None], optional

The path to write the CSV file to, by default None

data_typeQifDataType, optional

The type of data to convert to CSV, by default QifDataType.TRANSACTIONS

date_formatstr, optional

The date format to use when converting dates to strings, by default ‘%Y-%m-%d’

ignoreList[str], optional

A list of fields to ignore when converting to CSV, by default None

delimiterstr, optional

The delimiter to use when writing the CSV file, by default ‘,’

quote_characterstr, optional

The quote character to use when writing the CSV file, by default ‘”’

encodingstr, default=’utf-8’

The encoding to use when writing the CSV file

to_dataframe(data_type: QifDataType = QifDataType.TRANSACTIONS, ignore: Optional[List[str]] = None) pd.DataFrame

Convert part of the Qif object to a Pandas DataFrame. The data_type parameter can be used to specify which part of the Qif object to convert to a DataFrame. The default is to convert transactions.

Parameters
data_typeQifDataType, optional

The type of data to convert to a DataFrame, by default QifDataType.TRANSACTIONS

ignoreList[str], optional

A list of fields to ignore when converting to a DataFrame, by default None

Returns
pd.DataFrame

The data as a Pandas DataFrame

to_qif(path: Optional[Union[Path, str]] = None, date_format: str = '%Y-%m-%d', encoding: str = 'utf-8') str

Convert the Qif object to a QIF file

class quiffen.core.qif.QifDataType(value, names=<not given>, *values, module=None, qualname=None, type=None, start=1, boundary=None)

Bases: str, Enum

An Enum representing the different types of data that can be found in a Qif object.

Methods

capitalize(/)

Return a capitalized version of the string.

casefold(/)

Return a version of the string suitable for caseless comparisons.

center(width[, fillchar])

Return a centered string of length width.

count(sub[, start[, end]])

Return the number of non-overlapping occurrences of substring sub in string S[start:end].

encode(/[, encoding, errors])

Encode the string using the codec registered for encoding.

endswith(suffix[, start[, end]])

Return True if S ends with the specified suffix, False otherwise.

expandtabs(/[, tabsize])

Return a copy where all tab characters are expanded using spaces.

find(sub[, start[, end]])

Return the lowest index in S where substring sub is found, such that sub is contained within S[start:end].

format(*args, **kwargs)

Return a formatted version of S, using substitutions from args and kwargs.

format_map(mapping)

Return a formatted version of S, using substitutions from mapping.

index(sub[, start[, end]])

Return the lowest index in S where substring sub is found, such that sub is contained within S[start:end].

isalnum(/)

Return True if the string is an alpha-numeric string, False otherwise.

isalpha(/)

Return True if the string is an alphabetic string, False otherwise.

isascii(/)

Return True if all characters in the string are ASCII, False otherwise.

isdecimal(/)

Return True if the string is a decimal string, False otherwise.

isdigit(/)

Return True if the string is a digit string, False otherwise.

isidentifier(/)

Return True if the string is a valid Python identifier, False otherwise.

islower(/)

Return True if the string is a lowercase string, False otherwise.

isnumeric(/)

Return True if the string is a numeric string, False otherwise.

isprintable(/)

Return True if the string is printable, False otherwise.

isspace(/)

Return True if the string is a whitespace string, False otherwise.

istitle(/)

Return True if the string is a title-cased string, False otherwise.

isupper(/)

Return True if the string is an uppercase string, False otherwise.

join(iterable, /)

Concatenate any number of strings.

ljust(width[, fillchar])

Return a left-justified string of length width.

lower(/)

Return a copy of the string converted to lowercase.

lstrip([chars])

Return a copy of the string with leading whitespace removed.

maketrans(x[, y, z])

Return a translation table usable for str.translate().

partition(sep, /)

Partition the string into three parts using the given separator.

removeprefix(prefix, /)

Return a str with the given prefix string removed if present.

removesuffix(suffix, /)

Return a str with the given suffix string removed if present.

replace(old, new[, count])

Return a copy with all occurrences of substring old replaced by new.

rfind(sub[, start[, end]])

Return the highest index in S where substring sub is found, such that sub is contained within S[start:end].

rindex(sub[, start[, end]])

Return the highest index in S where substring sub is found, such that sub is contained within S[start:end].

rjust(width[, fillchar])

Return a right-justified string of length width.

rpartition(sep, /)

Partition the string into three parts using the given separator.

rsplit(/[, sep, maxsplit])

Return a list of the substrings in the string, using sep as the separator string.

rstrip([chars])

Return a copy of the string with trailing whitespace removed.

split(/[, sep, maxsplit])

Return a list of the substrings in the string, using sep as the separator string.

splitlines(/[, keepends])

Return a list of the lines in the string, breaking at line boundaries.

startswith(prefix[, start[, end]])

Return True if S starts with the specified prefix, False otherwise.

strip([chars])

Return a copy of the string with leading and trailing whitespace removed.

swapcase(/)

Convert uppercase characters to lowercase and lowercase characters to uppercase.

title(/)

Return a version of the string where each word is titlecased.

translate(table, /)

Replace each character in the string using the given translation table.

upper(/)

Return a copy of the string converted to uppercase.

zfill(width, /)

Pad a numeric string with zeros on the left, to fill a field of the given width.

ACCOUNTS = 'accounts'
CATEGORIES = 'categories'
CLASSES = 'classes'
INVESTMENTS = 'investments'
SECURITIES = 'securities'
TRANSACTIONS = 'transactions'

quiffen.core.transactions module

Module contents