Create and manage Odoo databases with ERPpeek or XML-RPC

Hi guys,

In this tutorial I will learn you how to connect to your Odoo database with ERPpeek or with simple XML-RPC calls. In this tutorial you will learn how to create new databases, how to install modules, how to add models and how to search for data in the database or write data in the database. These XML-RPC calls can be done from anywhere, also remotely.

In this example I will learn you how to create a new database, how to list the installed modules, how to install a module, how to add models and eventually how to search for data and add data in the database!
In this example I will be working with two ways: first with ERPpeek (which is an XML-RPC library wrapper which makes coding even easier) and I will then switch to XML-RPC calls, which are slightly more complex but do not need any remote libraries installed.

1. Installing ERPpeek

The first thing that you will need for this library is the ERPpeek library, which you can install very easily:

1.1 Creating a new database

One of the handy methods in ERPpeek is that you can very easily create a new database by command in a Python file. In this blogpost I will be separating all examples completely so I will also add the connection code again every time. This is because I will be switching from Erppeek to normal XML-RPC calls later on, to learn you both concepts.
Alright let us start! Create a new folder somewhere where you can create new Python files in. Now create a new Python file named ‘’. So, what do we need to create a new database? A database name, the path to the server (either on the same server or remote) and an administrator password for the admin user. A second thing that we need is to import the Python library ERPpeek, so we can use all the handy tools from there. The code will look like this:

So, we now have the credentials but how do we create the database? We can access all functions with ‘erppeek.client’ (you can find all methods in the ERPpeek documentation) which opens up a broad range of options. The first thing we need to do is create a client:

So we have the credentials now, we have a client and now we need to create the database! From here on we can acces everything we need from the variable ‘client’. Let us first add a validation to see that the database doesn’t exist yet and then create a new database with the function ‘create_database’! The code:

That is all you need to do! Just to be clear, here is whole code:

When you now execute this Python file it will create the new database for you. Save the Python file and execute it:

After a few seconds you will see the following result in your terminal:
New created database with ERPpeek

Congratulations, you’ve just created your first Odoo database by command. Now let us continue and see which modules are already installed.

1.2 Getting installed modules

A handy thing to know is which modules are installed in your Odoo, so let us create a new Python file named ‘’. Import ERPpeek and create a new client to connect with:

The first value for the erppeek.Client is the server IP (or localhost, which translates to and the port where the Odoo runs on, in this case 8080. The second value is the name of your database (ErpPeekDemoDatabase), the third is your Odoo username (admin) and the fourth is the user its password (admin).
So, we now have a working connection to the Odoo database and we now need to find out which modules are installed. This data is saved in the model ‘’, when the field ‘state’ is set to installed we know the module is installed. This translates to the following code with ERPpeek:

And for demo purposes let us simply print out this data in the terminal:

When you now execute this Python file it will it will print out all installed modules. Save the Python file and execute it:

After a few seconds you will see the following result in your terminal:
Installed modules

We now know which modules are installed, but wouldn’t it be great if we could install modules by command? Read on in chapter 1.3!

1.3 Installing a module

Create a new Python file and name it ‘’. Import ERPpeek and create a client just like you did in the previous examples:

We can now get all modules with ‘client.Modules’ and we can check if it is installed with the setting installed=False. When the module is in the state uninstalled we can install it with client.install. In this example I will check for the module sale and if it isn’t installed I will install it. The code:

When you now execute this Python file it will install the module for you (if it isn’t installed yet). Save the Python file and execute it:

After a few seconds you will see the following result in your terminal:
New created database
Do you notice anything interesting? Odoo will automatically check all dependencies and if some aren’t met they will be installed by Odoo! So we have now created a new database, we’ve checked which modules are installed and installed one which wasn’t installed yet. Now let us continue by adding a new contact to the ‘res.partner’ model.

1.4 Adding new records to a model with XML-RPC

So we’ve seen a few examples with ERPpeek now but we do not really need this library. We can just as easy do simple XML-rpc calls! It involves a bit more coding but it gives you the same possibilities as with the ERPpeek library. From here on I will continue this tutorial with XML-RPC calls for learning purposes. Do know that you can also use the ERPpeek library if you’d like to!

So we no longer need the ERPpeek library but we now need the library ‘xmlrpclib’. Import it and create a connection to the Odoo environment. We first need a ServerProxy which refers to the URL ‘localhost:xxxx/xmlrpc/common’ we then need an uid and then we need a socket to connect to. The code will look like this:

Do you see the similarities between the previous examples where we instantiated a client in one line? The working method is in essence the same, the code just looks slightly different and it is a bit more complex. What we did in one line in the previous examples now takes 6 lines but there is no difference in the possibilities.
We now have a client to connect with Odoo so let us now create a new record. The new record should be written in a dictionary format where you can add values for every field you would like to fill. For example I will create a new contact on the model ‘res.partner’ with the name ‘Fabien’ and the e-mail ‘’. This translates in the following code:

The last part is to write the new record to Odoo (with XML-RPC) by using sock.execute. The code:

What does this code do? It connects to the database with the credentials you’ve provided at the top of your script, it calls the model ‘res.partner’, uses the method ‘create’ (which creates a new record) and eventually we pass the dictionary to Odoo to write it in the database.

When you now execute this Python file it will create a new record in the database, on the model ‘res.partner’. Save the Python file and execute it:

After a second or two you will see the following result in your terminal:
New inserted contact
The new contact has been created with the id 7. When you now open up your Odoo and go to sales > contacts you will see the new contact:
New contact
Congratulations, you can now also connect with Odoo through XML-RPC calls and you can write data in the Odoo database! Now, let us learn how to fetch data from the database.

1.5 Searching for data in the database

Create a new Python file named ‘’, import the xmlrpclib, create credentials and create a socket connection:

Create a new sock.execute, just like you did in the previous example, but this time use the search method on the ‘res.partner’ model to get all contacts:

When we would execute the code at this point it would print us all the ID’s from all records on the model ‘res.partner’, but we as humans don’t know a lot by ids so let us translate these ids in to readable content! Loop over all the ids and create another sock.execute with the read function to get all the details. Finally print out the details of all contacts:

When you now execute this Python file it will search all records in the database, on the model ‘res.partner’. Save the Python file and execute it:

After a second or two you will see the following result in your terminal:
Details from inserted contacts

Congratulations! You can now also search for data in Odoo with XML-RPC!
There is one more thing I would like to learn you: how to create new models through XML-RPC calls.

1.6 Creating new models with XML-RPC calls

A rather often needed thing in Odoo is to create new models and this can also be done through XML-RPC calls! There is one downside though: you will need to create the model and field names starting with x_. This is not the case when you create a new model in a new module so it is probably better to create models that way.
In case you should do it from somewhere remote you can do it with calls though! This could be done with the XML-RPC library but we would need a lot more code so for this example I’m going back to ERPpeek!
Create a new Python file named ‘’, import ERPpeek and create a client:

In order to create a new model you will need access to the models ‘ir.model’ and ‘ir.model.fields’ so create two variables for this:

The first step is to create a new model, which will be empty, and after this is done you can add fields to it. First create a new model:

So what does this do? It creates a new model with the name ‘x_example_tutorial’ and the text will be ‘Example’ model. The model_proxy.create will finally create the new model.
Now that we have a new model the last thing we need to do is add fields to the model. Create a new dictionary with the field and all settings you want to specify:

This will create a new field with the name ‘x_name’, the type is a char with a length of 64 characters, the description of the field is ‘Firstname’ and we will simply add it on the just created model. field_proxy.create will eventually insert the new field in the database!

Thats it, congratulations! You now know quite a lot about XML-RPC calls and ERPpeek to access Odoo databases.

2. Conclusion

Using simple XML-RPC calls is a very powerfull tool to access and manage your Odoo database but when you use the ERPpeek library life gets even more easy. You can create new databases in a few lines of code, you can install modules and write to the database remotely.

Do you want to try the demo code and see the source code of this tutorial? You can view on my Github account.
Has this tutorial helped you, do you have any feedback or questions? Post away!


Odoo Experts

25 thoughts on “Create and manage Odoo databases with ERPpeek or XML-RPC

  1. Anti Nuga says:

    Love the articles You do, unrelated question to this topic though: Is there a way (if yes, then some pointers would be nice) to change Opportunity’s Next Action Date to the Date of a Scheduled call i created that is Related to that Opportunity?e.g. Scheduled call i related to a Opportunity and Odoo changes that Opportunities Next Action Date to the Scheduled Call’s Date. All the help is really appreciated.

    • Yenthe666 says:

      Hi Anti,

      Thanks a lot, nice to hear you like the articles. You could change the next action date whenever some action goes off or you could create an automated planner (scheduler) that checks all records every xx time to update the action date.
      P.s: sorry for the late response.

  2. Graham says:

    Hi Yves,
    I love your work! Really well written, easy to understand articles which have true value. Thank-you! Just one very tiny trivial thing which I am kind-of embarrassed to say but I feel it *may* help in some small way and I thought you’d want to know. I wanted to send an email directly to you so that others couldn’t read it but was unable to find an email address.
    It is a point of English and it appears at the top of all your articles that I have read:
    “I will teach you” (is correct) “I will learn you” (is incorrect)
    “You will learn” ( is correct)
    I hope this helps and doesn’t cause any offence (to anyone).

    • Yenthe666 says:

      Hi Graham,

      Thanks for the positive feedback. I didn’t even know that I will learn you is incorrect, I’ll blame me being not a native English person for that. 😉 Thanks for letting me know and correcting me! I will fix this as soon as possible in all my tutorials.

  3. Andy says:

    hi yenthe,
    i want to develop module to update price in product.supplierinfo everytime PO is confirmed, i’ve developed a module but instead of updating the record its create a new kinda bit confuse,can you help me?this is my module so far:
    def update_supplier(self):

    for line in self.order_line:
    if self.partner_id in line.product_id.seller_ids.mapped(‘name’) and len(line.product_id.seller_ids) <= 10:
    supplierinfo = {
    'price': line.price_unit,
    vals = {
    'seller_ids': [(0,0, supplierinfo)],


  4. Soprath says:

    Firstly, I tell you congrats for this article! It’s very interesting for my purpose but I have a question for you (if you can answer me) :

    In the new Web API’s documentation, I don’t find the service “xmlrpc/2/db” but “xmlrpc/2/common” and “xmlrpc/2/object are there… “xmlrpc/2/db” it’s deprecated in the new version?

    I need to use it for create, update (modules) databases… Because I’m working with Java and so I can’t use ERPPeek… Thank you in advance for your answer! Best regards

    • Yenthe666 says:

      Hi Soprath,

      Usually I always use Erppeek when I can, this handles all these things for you.. but since you use Java that is sadly no option. /xml/rpc/common is for common information such as the Odoo version, not for data querying. You should use the xmlrpc/2/object for querying against records, you can use execute_kw for calling specific data.

  5. Sonia says:

    Hi Yenthe,

    when I try to create a database,i have this:

    python $db
    Traceback (most recent call last):
    File “”, line 4, in
    DATABASE = sys.argv[1]
    IndexError: list index out of range

    Can you explain can you explain this error,please

    • Yenthe666 says:

      Hi Sonia,

      I’m not sure what command you’ve issued but list index out of range with sys.argv[1] means that your command is incorrect and is missing something. If this is default Odoo code and you’re trying to create a new database through the front-end please update your Odoo codebase. 🙂

  6. Salvador says:

    Hi Yenthe,

    Congrats for you articles. I really like the way you explain yourself.

    I have question related to your article. Is it posible to use ERPpeek to export data from the Odoo database ?

    • Yenthe666 says:

      Hi Salvador,

      Thanks a lot for the positive feedback, I’m happy to hear you like my articles. Yes you could use ERPpeek to export the data by first connecting to the remote database, fetching the data and then format it into a CSV file for example.

  7. henry says:

    Hello,congrats for you articles
    I changed the program above
    But I have some trouble
    Trouble shooting :*** psycopg2.InternalError: current transaction is aborted, commands ignored until end of transaction block

    can tell me how to do ?

Leave a Reply

Your email address will not be published. Required fields are marked *