finac


Namefinac JSON
Version 0.5.8 PyPI version JSON
download
home_pagehttps://github.com/alttch/finac
SummaryFinancial accounting library
upload_time2023-05-31 17:29:44
maintainer
docs_urlNone
authorAltertech
requires_python
licenseMIT
keywords
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # Finac - financial accounting for humans

Finac is a library and function set for Jupyter/ipython, which provides the
double-entry bookkeeping database.

Finac is simple, open and free. It can work with SQLite or any database
supported by SQLAlchemy (tested: SQLite, MySQL, PostgreSQL).

WARNING: SQLAlchemy 2 is NOT SUPPORTED until stabilized. If SQLAlchemy 2 is
required for other projects, run Finac in a dedicated virtual environment. 

<img src="https://img.shields.io/pypi/v/finac.svg" /> <img src="https://img.shields.io/badge/license-MIT-green" /> <img src="https://img.shields.io/badge/python-3.7%20%7C%203.8%20%7C%203.9%20%7C%203.10-blue.svg" />

Finac can be used either in the interactive mode with
[Jupyter](https://jupyter.org/), [Spyder-IDE](https://www.spyder-ide.org/),
ipython or other similar environment or Finac library can be embedded into 3rd
party projects. The library can be used in accounting applications and is
useful for fin-tech services.

Finac supports multiple currencies, simple transactions, double-entry
bookkeeping transactions, watches overdrafts, balance limits and has got many
useful features, which make accounting simple and fun.

## Install

```bash
pip3 install finac
```

Sources: https://github.com/alttch/finac

Documentation: https://finac.readthedocs.io/

## Updating

# from 0.4.10

```sql
ALTER TABLE transact ADD service bool;
UPDATE transact SET service=true WHERE d_created<'1970-01-03';
ALTER TABLE transact ADD FOREIGN KEY(chain_transact_id)
  REFERENCES transact(id) ON DELETE SET null;
```

# from 0.3.x

Starting from 0.4, Finac uses DateTime columns for:

* asset_rate.d
* transact.d
* transact.d_created
* transact.deleted

Depending to the database type, it's REQUIRED to convert these columns to
either DATETIME (SQLite, for MySQL DATETIME(6) recommended) or TIMESTAMPTZ
(PostgreSQL, with timezone).

## How to use in interactive mode

Finac database contains 3 entity types:

* **asset** currency, ISIN, stock code etc., currencies "USD" and "EUR" are
  created automatically. Finac does not separate assets into currencies,
  property and other. This allows creating applications for various areas using
  the single library.

* **account** bank account, counterparty account, tax account, special account
  etc. Everything is accounts :)

* **transaction** movements from (credit) / to (debit) and between accounts

Assets have got **rates** - the value of one asset, relative to other.

Transactions can be simple (no counterparty) or classic double-entry
bookkeeping (between debit and credit account).

```python
import finac as f
# init finac, 
f.init('/tmp/test.db')
# create a couple of accounts
f.account_create('acc1', 'USD')
f.account_create('acc2', 'USD')
f.account_create('depo', 'USD', 'saving')
# import initial balance with a simple transaction
f.tr('acc1', 10000, tag='import')
# move some assets to other accounts
f.mv(dt='acc2', ct='acc1', amount=2000)
f.mv(dt='depo', ct='acc1', amount=3000)
```

```python
# display statement for acc1
f.ls('acc1')
```

```
id     amount  cparty  tag     note  created              completed
-----------------------------------------------------------------------------
7   10 000.00          import        2019-10-26 03:04:02  2019-10-26 03:04:02
8   -2 000.00  ACC2                  2019-10-26 03:04:02  2019-10-26 03:04:02
9   -3 000.00  DEPO                  2019-10-26 03:04:02  2019-10-26 03:04:02
-----------------------------------------------------------------------------
Debit turnover: 10 000.00, credit turnover: 5 000.00

Net profit/loss: 5 000.00 USD
```

```python
# display summary for all accounts
f.ls()
```

```
account  type      asset     balance  balance USD
-------------------------------------------------
ACC1     current    USD     5 000.00     5 000.00
ACC2     current    USD     2 000.00     2 000.00
DEPO     saving     USD     3 000.00     3 000.00
-------------------------------------------------
Total: 10 000.00 USD
```

```python
# display summary only for current accounts
f.ls(tp='current')
```

```
account  type     asset     balance   balance USD
-------------------------------------------------
ACC1     current    USD     5 000.00     5 000.00
ACC2     current    USD     2 000.00     2 000.00
-------------------------------------------------
Total: 7 000.00 USD
```

```python
# display assets pie chart, (wrapper for matplotlib.pyplot, requires Jupyter,
# Spyder-IDE or a similar interactive environment)
f.pie()
```
<img src="https://github.com/alttch/finac/blob/master/doc/images/pie.png?raw=true" width="400" />

Note: when addressing currencies and accounts both in interactive and API mode,
account and asset codes should be used as object identifiers. **All codes are
case-insensitive**.

Inside database Finac uses numeric IDs to connect objects, so the codes can be
changed without any problems.

## Special features

### Lazy exchange

Finac can automatically move assets between accounts having different
currencies if exchange rate is set or specified in the transaction details:

```python
# create EUR account
f.account_create('acc5', 'eur')
# set exchange rate (in real life you would probably use cron job)
f.asset_set_rate('eur/usd', value=1.1)
f.mv(dt='acc5', ct='acc1', amount=100)
```

hoorah, account acc5 have got 100 EUR! And exchange rate was 1.1. Check it:

    >>> f.ls('acc1')

```
id     amount  cparty  tag     note  created              completed
-----------------------------------------------------------------------------
..............
..............
14    -110.00                        2019-10-26 03:15:41  2019-10-26 03:15:41
-----------------------------------------------------------------------------
```

    >>> f.ls('acc5')

```
id  amount  cparty  tag  note  created              completed
-----------------------------------------------------------------------
15  100.00                     2019-10-26 03:15:41  2019-10-26 03:15:41
-----------------------------------------------------------------------
Debit turnover: 100.00, credit turnover: 0.00

Net profit/loss: 100.00 EUR
```

As shown, there is no a counterparty account in the lazy exchange. This feature
is useful for personal accounting and special applications, but for
professional accounting, create counterparty exchange accounts should be
created and buy-sell transactions should be performed between them.

### Targets

Targets is a feature I have created Finac for. Consider there are account
balances in a bank and in the accounting. They differ in some amount and this
need to be recorded in the accounting with a single transaction.

But the problem is: there is a lot of transactions which should be sum up. Or
the difference between bank balance and accounting must be calculated manually.
Pretty common, eh? Don't do this, Finac has got targets.

Specifying targets instead of amount asks Finac to calculate transaction amount
by itself.

After the previous operation, there is *4,890.00* USD on "acc1" and consider
all except $1000 should be moved to "acc2". Let us do it:

    >>> f.mv(dt='acc2', ct='acc1', target_ct=1000)

```
id     amount  cparty  tag     note  created              completed
-----------------------------------------------------------------------------
......
......
16  -3 890.00  ACC2                  2019-10-26 03:25:56  2019-10-26 03:25:56
-----------------------------------------------------------------------------
Debit turnover: 10 000.00, credit turnover: 9 000.00

Net profit/loss: 1 000.00 USD

```

The transaction amount is automatically calculated. Lazy people are happy :)

If the debit account balance target should be specified, *target_dt*
function argument can be used. Note: calculated transaction amount must be
always greater than zero (if credit account target higher than its current
balance is specified, *ValueError* is raised)

For simple transactions (*f.tr(...))*), use *target=*.

### Transaction templates

Example: there is a repeating payment orders in a bank, which pay office
utility bills every 5th day of month, plus automatically move $100 to a saving
account. To fill this into accounting, YAML transaction template can be
used:

```yaml
transactions:
  - account: acc1
    amount: 200
    tag: electricity
    note: energy company deposit
  - account: acc1
    amount: 800
    tag: rent
    note: office rent
  - dt: depo
    ct: acc1
    amount: 200
    tag: savings
    note: rainy day savings
```

then create a cron job which calls *f.transaction_apply("/path/to/file.yml")*
and that is it.

Actually, transaction templates are useful for any repeating operations. The
same arguments, as for the core functions, can be specified.

### Number formatting

Finac does not use system locale. If amounts and targets are inputted as
strings, they can be specified in any format and Finac tries converting strings
into float numeric automatically. The following values for amounts and
targets are valid and are automatically parsed:

* 1 000,00 = 1000.0
* 1,000.00 = 1000.0
* 1.000,00 = 1000.0
* 1,000.00 = 1000.0
* 10,0 = 10.0
* 10.0 = 10.0

### Passive accounts

If account is passive, its assets are decremented from totals. To create
passive account, *passive* argument must be used:

```python
f.account_create('passive1', 'usd', passive=True)
```

Accounts of types "tax", "supplier" and "finagent" are passive by default.

### Data multiplier

Depending on data, it may be useful to store numeric values in the database as
integers instead of floats. Finac library has got a built-in data multiplier
feature. To enable it, set *multiplier=N* in *finac.init()* method, e.g.
*multiplier=1000*. This makes Finac to store integers into tables and use the
max precision of 3 digits after comma.

Note: table fields must be manually converted to numeric/integer types. In 
production databases the field values must be also manually multiplied.

Full list of tables and fields, required to be converted, is available in the
dict *finac.core.multiply_fields*.

Note: the multiplier can be used only with integer and numeric(X) field types,
as core conversion functions always return rounded value.

## How to embed Finac library into own project

See [Finac documentation](https://finac.readthedocs.io/) for core function API
details.

## Client-server mode and HTTP API

See [Finac documentation](https://finac.readthedocs.io/) for server mode and
HTTP API details.

## Enterprise server and support

Want to integrate Finac into an own enterprise app or service? Need a support?
Check [Finac Enterprise Server](https://www.altertech.com/products/fes/).



            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/alttch/finac",
    "name": "finac",
    "maintainer": "",
    "docs_url": null,
    "requires_python": "",
    "maintainer_email": "",
    "keywords": "",
    "author": "Altertech",
    "author_email": "div@altertech.com",
    "download_url": "https://files.pythonhosted.org/packages/23/8f/e81e5b1cdc25101dbbbaa3a1a61b443f40c4b86c4a53fe5d716b17ce3f93/finac-0.5.8.tar.gz",
    "platform": null,
    "description": "# Finac - financial accounting for humans\n\nFinac is a library and function set for Jupyter/ipython, which provides the\ndouble-entry bookkeeping database.\n\nFinac is simple, open and free. It can work with SQLite or any database\nsupported by SQLAlchemy (tested: SQLite, MySQL, PostgreSQL).\n\nWARNING: SQLAlchemy 2 is NOT SUPPORTED until stabilized. If SQLAlchemy 2 is\nrequired for other projects, run Finac in a dedicated virtual environment. \n\n<img src=\"https://img.shields.io/pypi/v/finac.svg\" /> <img src=\"https://img.shields.io/badge/license-MIT-green\" /> <img src=\"https://img.shields.io/badge/python-3.7%20%7C%203.8%20%7C%203.9%20%7C%203.10-blue.svg\" />\n\nFinac can be used either in the interactive mode with\n[Jupyter](https://jupyter.org/), [Spyder-IDE](https://www.spyder-ide.org/),\nipython or other similar environment or Finac library can be embedded into 3rd\nparty projects. The library can be used in accounting applications and is\nuseful for fin-tech services.\n\nFinac supports multiple currencies, simple transactions, double-entry\nbookkeeping transactions, watches overdrafts, balance limits and has got many\nuseful features, which make accounting simple and fun.\n\n## Install\n\n```bash\npip3 install finac\n```\n\nSources: https://github.com/alttch/finac\n\nDocumentation: https://finac.readthedocs.io/\n\n## Updating\n\n# from 0.4.10\n\n```sql\nALTER TABLE transact ADD service bool;\nUPDATE transact SET service=true WHERE d_created<'1970-01-03';\nALTER TABLE transact ADD FOREIGN KEY(chain_transact_id)\n  REFERENCES transact(id) ON DELETE SET null;\n```\n\n# from 0.3.x\n\nStarting from 0.4, Finac uses DateTime columns for:\n\n* asset_rate.d\n* transact.d\n* transact.d_created\n* transact.deleted\n\nDepending to the database type, it's REQUIRED to convert these columns to\neither DATETIME (SQLite, for MySQL DATETIME(6) recommended) or TIMESTAMPTZ\n(PostgreSQL, with timezone).\n\n## How to use in interactive mode\n\nFinac database contains 3 entity types:\n\n* **asset** currency, ISIN, stock code etc., currencies \"USD\" and \"EUR\" are\n  created automatically. Finac does not separate assets into currencies,\n  property and other. This allows creating applications for various areas using\n  the single library.\n\n* **account** bank account, counterparty account, tax account, special account\n  etc. Everything is accounts :)\n\n* **transaction** movements from (credit) / to (debit) and between accounts\n\nAssets have got **rates** - the value of one asset, relative to other.\n\nTransactions can be simple (no counterparty) or classic double-entry\nbookkeeping (between debit and credit account).\n\n```python\nimport finac as f\n# init finac, \nf.init('/tmp/test.db')\n# create a couple of accounts\nf.account_create('acc1', 'USD')\nf.account_create('acc2', 'USD')\nf.account_create('depo', 'USD', 'saving')\n# import initial balance with a simple transaction\nf.tr('acc1', 10000, tag='import')\n# move some assets to other accounts\nf.mv(dt='acc2', ct='acc1', amount=2000)\nf.mv(dt='depo', ct='acc1', amount=3000)\n```\n\n```python\n# display statement for acc1\nf.ls('acc1')\n```\n\n```\nid     amount  cparty  tag     note  created              completed\n-----------------------------------------------------------------------------\n7   10 000.00          import        2019-10-26 03:04:02  2019-10-26 03:04:02\n8   -2 000.00  ACC2                  2019-10-26 03:04:02  2019-10-26 03:04:02\n9   -3 000.00  DEPO                  2019-10-26 03:04:02  2019-10-26 03:04:02\n-----------------------------------------------------------------------------\nDebit turnover: 10 000.00, credit turnover: 5 000.00\n\nNet profit/loss: 5 000.00 USD\n```\n\n```python\n# display summary for all accounts\nf.ls()\n```\n\n```\naccount  type      asset     balance  balance USD\n-------------------------------------------------\nACC1     current    USD     5 000.00     5 000.00\nACC2     current    USD     2 000.00     2 000.00\nDEPO     saving     USD     3 000.00     3 000.00\n-------------------------------------------------\nTotal: 10 000.00 USD\n```\n\n```python\n# display summary only for current accounts\nf.ls(tp='current')\n```\n\n```\naccount  type     asset     balance   balance USD\n-------------------------------------------------\nACC1     current    USD     5 000.00     5 000.00\nACC2     current    USD     2 000.00     2 000.00\n-------------------------------------------------\nTotal: 7 000.00 USD\n```\n\n```python\n# display assets pie chart, (wrapper for matplotlib.pyplot, requires Jupyter,\n# Spyder-IDE or a similar interactive environment)\nf.pie()\n```\n<img src=\"https://github.com/alttch/finac/blob/master/doc/images/pie.png?raw=true\" width=\"400\" />\n\nNote: when addressing currencies and accounts both in interactive and API mode,\naccount and asset codes should be used as object identifiers. **All codes are\ncase-insensitive**.\n\nInside database Finac uses numeric IDs to connect objects, so the codes can be\nchanged without any problems.\n\n## Special features\n\n### Lazy exchange\n\nFinac can automatically move assets between accounts having different\ncurrencies if exchange rate is set or specified in the transaction details:\n\n```python\n# create EUR account\nf.account_create('acc5', 'eur')\n# set exchange rate (in real life you would probably use cron job)\nf.asset_set_rate('eur/usd', value=1.1)\nf.mv(dt='acc5', ct='acc1', amount=100)\n```\n\nhoorah, account acc5 have got 100 EUR! And exchange rate was 1.1. Check it:\n\n    >>> f.ls('acc1')\n\n```\nid     amount  cparty  tag     note  created              completed\n-----------------------------------------------------------------------------\n..............\n..............\n14    -110.00                        2019-10-26 03:15:41  2019-10-26 03:15:41\n-----------------------------------------------------------------------------\n```\n\n    >>> f.ls('acc5')\n\n```\nid  amount  cparty  tag  note  created              completed\n-----------------------------------------------------------------------\n15  100.00                     2019-10-26 03:15:41  2019-10-26 03:15:41\n-----------------------------------------------------------------------\nDebit turnover: 100.00, credit turnover: 0.00\n\nNet profit/loss: 100.00 EUR\n```\n\nAs shown, there is no a counterparty account in the lazy exchange. This feature\nis useful for personal accounting and special applications, but for\nprofessional accounting, create counterparty exchange accounts should be\ncreated and buy-sell transactions should be performed between them.\n\n### Targets\n\nTargets is a feature I have created Finac for. Consider there are account\nbalances in a bank and in the accounting. They differ in some amount and this\nneed to be recorded in the accounting with a single transaction.\n\nBut the problem is: there is a lot of transactions which should be sum up. Or\nthe difference between bank balance and accounting must be calculated manually.\nPretty common, eh? Don't do this, Finac has got targets.\n\nSpecifying targets instead of amount asks Finac to calculate transaction amount\nby itself.\n\nAfter the previous operation, there is *4,890.00* USD on \"acc1\" and consider\nall except $1000 should be moved to \"acc2\". Let us do it:\n\n    >>> f.mv(dt='acc2', ct='acc1', target_ct=1000)\n\n```\nid     amount  cparty  tag     note  created              completed\n-----------------------------------------------------------------------------\n......\n......\n16  -3 890.00  ACC2                  2019-10-26 03:25:56  2019-10-26 03:25:56\n-----------------------------------------------------------------------------\nDebit turnover: 10 000.00, credit turnover: 9 000.00\n\nNet profit/loss: 1 000.00 USD\n\n```\n\nThe transaction amount is automatically calculated. Lazy people are happy :)\n\nIf the debit account balance target should be specified, *target_dt*\nfunction argument can be used. Note: calculated transaction amount must be\nalways greater than zero (if credit account target higher than its current\nbalance is specified, *ValueError* is raised)\n\nFor simple transactions (*f.tr(...))*), use *target=*.\n\n### Transaction templates\n\nExample: there is a repeating payment orders in a bank, which pay office\nutility bills every 5th day of month, plus automatically move $100 to a saving\naccount. To fill this into accounting, YAML transaction template can be\nused:\n\n```yaml\ntransactions:\n  - account: acc1\n    amount: 200\n    tag: electricity\n    note: energy company deposit\n  - account: acc1\n    amount: 800\n    tag: rent\n    note: office rent\n  - dt: depo\n    ct: acc1\n    amount: 200\n    tag: savings\n    note: rainy day savings\n```\n\nthen create a cron job which calls *f.transaction_apply(\"/path/to/file.yml\")*\nand that is it.\n\nActually, transaction templates are useful for any repeating operations. The\nsame arguments, as for the core functions, can be specified.\n\n### Number formatting\n\nFinac does not use system locale. If amounts and targets are inputted as\nstrings, they can be specified in any format and Finac tries converting strings\ninto float numeric automatically. The following values for amounts and\ntargets are valid and are automatically parsed:\n\n* 1 000,00 = 1000.0\n* 1,000.00 = 1000.0\n* 1.000,00 = 1000.0\n* 1,000.00 = 1000.0\n* 10,0 = 10.0\n* 10.0 = 10.0\n\n### Passive accounts\n\nIf account is passive, its assets are decremented from totals. To create\npassive account, *passive* argument must be used:\n\n```python\nf.account_create('passive1', 'usd', passive=True)\n```\n\nAccounts of types \"tax\", \"supplier\" and \"finagent\" are passive by default.\n\n### Data multiplier\n\nDepending on data, it may be useful to store numeric values in the database as\nintegers instead of floats. Finac library has got a built-in data multiplier\nfeature. To enable it, set *multiplier=N* in *finac.init()* method, e.g.\n*multiplier=1000*. This makes Finac to store integers into tables and use the\nmax precision of 3 digits after comma.\n\nNote: table fields must be manually converted to numeric/integer types. In \nproduction databases the field values must be also manually multiplied.\n\nFull list of tables and fields, required to be converted, is available in the\ndict *finac.core.multiply_fields*.\n\nNote: the multiplier can be used only with integer and numeric(X) field types,\nas core conversion functions always return rounded value.\n\n## How to embed Finac library into own project\n\nSee [Finac documentation](https://finac.readthedocs.io/) for core function API\ndetails.\n\n## Client-server mode and HTTP API\n\nSee [Finac documentation](https://finac.readthedocs.io/) for server mode and\nHTTP API details.\n\n## Enterprise server and support\n\nWant to integrate Finac into an own enterprise app or service? Need a support?\nCheck [Finac Enterprise Server](https://www.altertech.com/products/fes/).\n\n\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "Financial accounting library",
    "version": "0.5.8",
    "project_urls": {
        "Homepage": "https://github.com/alttch/finac"
    },
    "split_keywords": [],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "238fe81e5b1cdc25101dbbbaa3a1a61b443f40c4b86c4a53fe5d716b17ce3f93",
                "md5": "1539d9a3e222edef16fe32b1565841ca",
                "sha256": "60448834e56c9ea88af4132a98c2459aa6137b4f50c00a1958fe9866f945a12c"
            },
            "downloads": -1,
            "filename": "finac-0.5.8.tar.gz",
            "has_sig": false,
            "md5_digest": "1539d9a3e222edef16fe32b1565841ca",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": null,
            "size": 38027,
            "upload_time": "2023-05-31T17:29:44",
            "upload_time_iso_8601": "2023-05-31T17:29:44.758431Z",
            "url": "https://files.pythonhosted.org/packages/23/8f/e81e5b1cdc25101dbbbaa3a1a61b443f40c4b86c4a53fe5d716b17ce3f93/finac-0.5.8.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-05-31 17:29:44",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "alttch",
    "github_project": "finac",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "lcname": "finac"
}
        
Elapsed time: 0.07579s