KeyError on starting flask with Tryton

I’m trying to run the example but I get the following KeyError:

Traceback (most recent call last):
  File "/home/yoel/Development/tryton/marketing/app/", line 11, in <module>
    User = tryton.pool.get('res.user')
  File "/home/yoel/Development/tryton/marketing/venv/lib/python3.6/site-packages/trytond/", line 179, in get
    return self._pool[self.database_name][type][name]
KeyError: 'res.user'

This is how looks my file:

from flask import Flask
from flask_tryton import Tryton
app = Flask(__name__)

app.config['TRYTON_CONFIG'] = '/home/yoel/Development/tryton/5.0/full/conf/trytond.conf'
app.config['TRYTON_DATABASE'] = 'tryton_full_new'
app.config['TRYTON_USER'] = 1

tryton = Tryton(app, configure_jinja=True)
User = tryton.pool.get('res.user')

def default_context():
    return User.get_preferences(context_only=True)

def hello():
    user, =[('login', '=', 'admin')])
    return '%s, Hello World!' %

def user(user):

def users(users):
    return ', '.join( for u in users)

if __name__ == '__main__':, port=5000)

Could anyone tell me how can I make it work? Thanks.

You need a working trytond server first. Flask_tryton it’s another interface for your existing trytond server (Like tryton client ). Did you check trytond.conf? Are you able to connect using tryton client on same server ?


Make sure your TRYTON_CONFIG and TRYTON_DATABASE variables are well configured.

AFAIK you don’t need to setup TRYTON_USER (default is used, 0):

I’m sure you will find more information here

My trytond.conf it’s fine and working, I’m able to connect by web and desktop client

uri = postgresql://tryton_full_new:tryton_full_new@
path = /home/yoel/Development/tryton/5.0/full/attach
list = True
retry = 5
language = es_419

timeout = 7200

listen =
root = /home/yoel/Development/tryton/5.0/full/sao

uri = smtp://localhost:25
from = Tryton ERP Perú <> 

sunat_invoicing = /home/yoel/Development/tryton/5.0/full/sunat/invoices
debug = development



I come from there, looking for some help here. About the variables I edited my post and I replied to @German

Are you using a virtualenv?

If yes, You need to active tryton_flask inside the same virtualenv that trytond is running.

Yes, I’m using virtualenv, I’ve moved the Flask script to the same virtualenv that uses Tryton, but I’m still getting the same KeyError that I posted at the beginning of this topic.

Is it imperative use the same virtualenv for Tryton and Flask?

“There are three configuration options available” says the package:

>>> from flask import Flask
>>> from flask_tryton import Tryton
>>> app = Flask(__name__)
>>> app.config['TRYTON_DATABASE'] = 'tryton_full_new'
>>> tryton = Tryton(app, configure_jinja=True)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/yoel/Development/tryton/new/full/env/lib/python3.6/site-packages/", line 52, in __init__
  File "/home/yoel/Development/tryton/new/full/env/lib/python3.6/site-packages/", line 67, in init_app
    with Transaction().start(database, user, readonly=True):
  File "/home/yoel/Development/tryton/new/full/env/lib/python3.6/site-packages/trytond/", line 107, in start
    database = backend.Database(database_name).connect()
  File "/home/yoel/Development/tryton/new/full/env/lib/python3.6/site-packages/trytond/backend/sqlite/", line 344, in connect
    raise IOError('Database "%s" doesn\'t exist!' % path)
OSError: Database "/home/yoel/db/tryton_full_new.sqlite" doesn't exist!

Why is looking for a .sqlite database? I mean, it’s not clear if the TRYTON_DATABASE is just a string or an URI

Yes, you should run the same code so flask is able to load the Tryton modules.

Because you did not set up any trytond.conf file, so it’s using the default one which uses sqlite.
You should set the TRYTOND_CONFIG environment variable pointing to the route of your configuration file to use a diferent backend.

A string indicating the name of the database.