# Setting Up The Database With Proteus

**URL:** https://discuss.tryton.org/t/setting-up-the-database-with-proteus/6824
**Category:** System Administrator
**Created:** [December 29, 2023, 9:21pm UTC](https://discuss.tryton.org/t/setting-up-the-database-with-proteus/6824 "2023-12-29T21:21:33Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![Toni](https://discuss-cdn.tryton.org/letter_avatar_proxy/v4/letter/t/8797f3/32.png) [@Toni](https://discuss.tryton.org/u/Toni)
#### Post date: [December 29, 2023, 9:21pm UTC](https://discuss.tryton.org/t/setting-up-the-database-with-proteus/6824/1 "2023-12-29T21:21:34Z")

</div>

Hi,

I want to play with automatic database setup and thought I could use ‘proteus’ for that. Since I’m going to have many iterations until the code does what it should do, I wanted to use SQLite’s memory database instead of PostgreSQL, which is very, very slow. However, when I follow the instructions given here:

> **[Tryton Scripting Client — Library to access Tryton server as a client](https://docs.tryton.org/latest/client-library/)**

I’ll only get a traceback saying that the ‘ir\_module’ is not available. Since it’s an in-memory database, I also can’t use tryton-admin to set the database up. Is there a better way than just lifting all the relevant code from ‘tryton-admin’ and the modules it imports?

Thanks,  
Toni

---

<div class="post-metadata">

### Author: ![maxx](https://discuss-cdn.tryton.org/user_avatar/discuss.tryton.org/maxx/32/2320_2.png) [@maxx](https://discuss.tryton.org/u/maxx)
#### Post date: [December 29, 2023, 10:59pm UTC](https://discuss.tryton.org/t/setting-up-the-database-with-proteus/6824/2 "2023-12-29T22:59:24Z")

</div>

Hi,

You could check the demo script here:

> **[tryton\_demo.py · 77d417e6bf5962a76edd583c0b7afb2172ce41b3 · Tryton / Tools /...](https://foss.heptapod.net/tryton/tools/maintenance/-/blob/77d417e6bf5962a76edd583c0b7afb2172ce41b3/tryton_demo.py)**
>
> Tools for maintenace

---

<div class="post-metadata">

### Author: ![Toni](https://discuss-cdn.tryton.org/letter_avatar_proxy/v4/letter/t/8797f3/32.png) [@Toni](https://discuss.tryton.org/u/Toni)
#### Post date: [December 29, 2023, 11:13pm UTC](https://discuss.tryton.org/t/setting-up-the-database-with-proteus/6824/3 "2023-12-29T23:13:16Z")

</div>

Hi Maxime,  
thank you for the idea, but the problem happens already at the secibd line from the documentation that I referenced:

```auto
>>> from proteus import config as pconfig
>>> config = pconfig.set_trytond('sqlite:///:memory:')
/home/toni/.virtualenvs/tryton/lib/python3.11/site-packages/csb43/i18n/ __init__.py:7: DeprecationWarning: pkg_resources is deprecated as an API. See https://setuptools.pypa.i
o/en/latest/pkg_resources.html
  import pkg_resources
/home/toni/.virtualenvs/tryton/lib/python3.11/site-packages/csb43/i18n/ __init__.py:21: DeprecationWarning: Use setlocale(), getencoding() and getlocale() instead
  lc, encoding = locale.getdefaultlocale()
/home/toni/.virtualenvs/tryton/lib/python3.11/site-packages/braintree/dispute.py:80: DeprecationWarning: Use ProtectionLevel enum instead
  warnings.warn("Use ProtectionLevel enum instead", DeprecationWarning)
/home/toni/.virtualenvs/tryton/lib/python3.11/site-packages/braintree/search.py:79: DeprecationWarning: Use protection_level parameter instead
  warnings.warn("Use protection_level parameter instead", DeprecationWarning)
/home/toni/.virtualenvs/tryton/lib/python3.11/site-packages/zeep/utils.py:1: DeprecationWarning: 'cgi' is deprecated and slated for removal in Python 3.13
  import cgi
Traceback (most recent call last):
  File "<input>", line 1, in <module>
    config = pconfig.set_trytond('sqlite:///:memory:')
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/toni/.virtualenvs/tryton/lib/python3.11/site-packages/proteus/config.py", line 329, in set_trytond
    _CONFIG.current = TrytondConfig(database, user, config_file=config_file)
                      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/toni/.virtualenvs/tryton/lib/python3.11/site-packages/proteus/config.py", line 282, in __init__
    self.pool.init()
  File "/home/toni/.virtualenvs/tryton/lib/python3.11/site-packages/trytond/pool.py", line 167, in init
    restart = not load_modules(
                  ^^^^^^^^^^^^^
  File "/home/toni/.virtualenvs/tryton/lib/python3.11/site-packages/trytond/modules/ __init__.py", line 388, in load_modules
    with Transaction().start(database_name, 0):
         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/toni/.virtualenvs/tryton/lib/python3.11/site-packages/trytond/transaction.py", line 216, in start
    Cache.sync(self)
  File "/home/toni/.virtualenvs/tryton/lib/python3.11/site-packages/trytond/cache.py", line 252, in sync
    cursor.execute(*table.select(
sqlite3.OperationalError: no such table: ir_cache

```

The script you recommended, also has the same problem. It even doesn’t recognize the database setting and insists on opening an SQLite database file in a completely unrelated location:

```auto
$ ./tryton_demo.py --config=test.conf
/home/toni/.virtualenvs/tryton/lib/python3.11/site-packages/passlib/utils/ __init__.py:854: DeprecationWarning: 'crypt' is deprecated and slated for removal in Python 3.13
  from crypt import crypt as _crypt
/home/toni/.virtualenvs/tryton/lib/python3.11/site-packages/braintree/dispute.py:80: DeprecationWarning: Use ProtectionLevel enum instead
  warnings.warn("Use ProtectionLevel enum instead", DeprecationWarning)
/home/toni/.virtualenvs/tryton/lib/python3.11/site-packages/braintree/search.py:79: DeprecationWarning: Use protection_level parameter instead
  warnings.warn("Use protection_level parameter instead", DeprecationWarning)
/home/toni/.virtualenvs/tryton/lib/python3.11/site-packages/csb43/i18n/ __init__.py:7: DeprecationWarning: pkg_resources is deprecated as an API. See https://setuptools.pypa.io/en/latest/pkg_resources.html
  import pkg_resources
/home/toni/.virtualenvs/tryton/lib/python3.11/site-packages/csb43/i18n/ __init__.py:21: DeprecationWarning: Use setlocale(), getencoding() and getlocale() instead
  lc, encoding = locale.getdefaultlocale()
/home/toni/.virtualenvs/tryton/lib/python3.11/site-packages/zeep/utils.py:1: DeprecationWarning: 'cgi' is deprecated and slated for removal in Python 3.13
  import cgi
Traceback (most recent call last):
  File "/home/toni/.virtualenvs/tryton/lib/python3.11/site-packages/trytond/transaction.py", line 179, in start
    database = backend.Database(database_name).connect()
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/toni/.virtualenvs/tryton/lib/python3.11/site-packages/trytond/backend/sqlite/database.py", line 365, in connect
    self._make_uri(), uri=True,
    ^^^^^^^^^^^^^^^^
  File "/home/toni/.virtualenvs/tryton/lib/python3.11/site-packages/trytond/backend/sqlite/database.py", line 439, in _make_uri
    raise IOError("Database '%s' doesn't exist!" % db_path)
OSError: Database '/home/toni/db/demo.sqlite' doesn't exist!

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/toni/.virtualenvs/tryton/lib/python3.11/site-packages/trytond/transaction.py", line 239, in stop
    self.rollback()
  File "/home/toni/.virtualenvs/tryton/lib/python3.11/site-packages/trytond/transaction.py", line 356, in rollback
    for datamanager in self._datamanagers:
                       ^^^^^^^^^^^^^^^^^^
AttributeError: 'Transaction' object has no attribute '_datamanagers'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/toni/mnt/tryton/setups/./tryton_demo.py", line 1014, in <module>
    main(options.database, options.modules, options.demo_password,
  File "/home/toni/mnt/tryton/setups/./tryton_demo.py", line 917, in main
    config = set_config(database, config_file)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/toni/mnt/tryton/setups/./tryton_demo.py", line 26, in set_config
    return pconfig.set_trytond(database, config_file=config_file)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/toni/.virtualenvs/tryton/lib/python3.11/site-packages/proteus/config.py", line 329, in set_trytond
    _CONFIG.current = TrytondConfig(database, user, config_file=config_file)
                      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/toni/.virtualenvs/tryton/lib/python3.11/site-packages/proteus/config.py", line 282, in __init__
    self.pool.init()
  File "/home/toni/.virtualenvs/tryton/lib/python3.11/site-packages/trytond/pool.py", line 167, in init
    restart = not load_modules(
                  ^^^^^^^^^^^^^
  File "/home/toni/.virtualenvs/tryton/lib/python3.11/site-packages/trytond/modules/ __init__.py", line 388, in load_modules
    with Transaction().start(database_name, 0):
         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/toni/.virtualenvs/tryton/lib/python3.11/site-packages/trytond/transaction.py", line 218, in start
    self.stop(False)
  File "/home/toni/.virtualenvs/tryton/lib/python3.11/site-packages/trytond/transaction.py", line 241, in stop
    self.database.put_connection(
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
AttributeError: 'NoneType' object has no attribute 'put_connection'

```

FWIW, I am using a dedicated virtualenv with Tryton 7.0.3 on a Debian Bookworm machine.

---

<div class="post-metadata">

### Author: ![ced](https://discuss-cdn.tryton.org/user_avatar/discuss.tryton.org/ced/32/1237_2.png) [@ced](https://discuss.tryton.org/u/ced)
#### Post date: [December 30, 2023, 12:56am UTC](https://discuss.tryton.org/t/setting-up-the-database-with-proteus/6824/4 "2023-12-30T00:56:40Z")

</div>

Proteus does not setup the database. it must be setup by `trytond-admin` but this forbid to use memory database because they are only available to the current process.  
One way to use the memory database is to use the `create_db` method of `trytond.tests.test_tryton` but importing the `trytond.tests` may have undesirable effect for a production setup.

---

<div class="post-metadata">

### Author: ![Toni](https://discuss-cdn.tryton.org/letter_avatar_proxy/v4/letter/t/8797f3/32.png) [@Toni](https://discuss.tryton.org/u/Toni)
#### Post date: [December 30, 2023, 1:56pm UTC](https://discuss.tryton.org/t/setting-up-the-database-with-proteus/6824/5 "2023-12-30T13:56:46Z")

</div>

Hi Cedric,

thank you for the hint! I want to use a memory database to speed up development of something, but not for production use. I have some clunky code that does the database setup, but was hoping to get rid of it. So the next stop is to figure whether ‘create\_db’ is a better option. 🙂
