# How to setup environment to create a new module

**URL:** https://discuss.tryton.org/t/how-to-setup-environment-to-create-a-new-module/1616
**Category:** Developer
**Created:** [July 29, 2019, 2:30pm UTC](https://discuss.tryton.org/t/how-to-setup-environment-to-create-a-new-module/1616 "2019-07-29T14:30:00Z")
**Posts on this page:** 1
**Showing post:** 2

<div class="post-metadata">

### Author: ![wifasoi](https://discuss-cdn.tryton.org/letter_avatar_proxy/v4/letter/w/ed655f/32.png) [@wifasoi](https://discuss.tryton.org/u/wifasoi)
#### Post date: [July 29, 2019, 4:28pm UTC](https://discuss.tryton.org/t/how-to-setup-environment-to-create-a-new-module/1616/2 "2019-07-29T16:28:45Z")

</div>

## Basic setup

For creating the basic folder structure and setup.py you can use cookie-cutter (need to install cookiecutter first via pip/system packet manager)

> **[GitHub - tryton/cookiecutter-tryton: Mirror of cookiecutter-tryton](https://github.com/tryton/cookiecutter-tryton)**
>
> Mirror of cookiecutter-tryton

then you can execute:  
`cookiecutter hg+https://hg.tryton.org/cookiecutter`  
cookiecutter will ask you some question (like the project name), then will create a folder with all the necessary thing to start developing with tryton

### tryton.cfg

First you need to change the tryton.cfg; this file is responsible for:

- tell setup.py witch version of tryton this module support
- tell setup.py your tryton module dependecy
- tell the xml file to include (the one that define the database record, not the views)

### how to install your module

I strongly suggest to use a [virtual-environment](https://docs.python.org/3/tutorial/venv.html) for development. The you can simply `python setup.py install` to install all your dependecy defined in the `tryton.cfg` (you can install the dependency manually if you want).  
Every time you make a change you need to reinstall the module, unless you use a workaround (`python setup.py develop` doesn’t work unfortunally)

### how install the module in editable mode (for developing it)

When developing, installing the module every time you modify it can be time consuming,  
a sane way to solve this problem is to install it id editable mode:  
`python setup.py develop`  
_ **This will not work if your module folder doesn’t match the module name!** _  
This will create a simlink in the correct folder for you.

### How to setup your playground/manual testing environment

Trytond needs a database, fortunately you can be lazy about it and use sqlite. For this you need create a config file, the minimum required is:

```auto
[database]
path=/path/where/sqlite/dbs/are/stored

```

or optionally set the environment variable  
`export TRYTOND_DATABASE__PATH=/path/where/sqlite/dbs/are/stored`  
[explained in [https://trytond.readthedocs.io/en/latest/topics/configuration.html](https://trytond.readthedocs.io/en/latest/topics/configuration.html)]

The only thing missing is to create a empty file in the `/path/where/sqlite/dbs/are/stored` folder, don’t forget to ad the `.sqlite` extention or tryton will not recognize it. You can have multiple sqlite db in the same folder.  
example:

```plaintext
touch /path/where/sqlite/dbs/are/stored/testplzignore.sqlite

```

### Prime the database

You need to prime your database, this can be accomplished with the `trytond-admin` command.  
This will create all the necessary table for tryton to work, and set the admin password.  
The detail are explained in the [documentation](https://trytond.readthedocs.io/en/latest/topics/setup_database.html)

```bash
# with the configfile
trytond-admin -c configfile.cfg -d dbfilename --all

#with the enviroment variable
#export TRYTOND_DATABASE__PATH=/path/where/sqlite/dbs/are/stored
trytond-admin -d dbfilename --all

```

where `dbfilename` is the filename of the db without the .sqlite extention.

### Activate your module

After “priming” you need to activate your module, this can be done via the client gui or via command line:

```bash
#with the enviroment variable
#export TRYTOND_DATABASE__PATH=/path/where/sqlite/dbs/are/stored
trytond-admin -d dbfilename -u moduletoactivate --activate-dependecies

```

### Update your module

if you modify some xml file, you need to update the db and usually relaunch the client. this can be archived with:

```bash
#with the enviroment variable
#export TRYTOND_DATABASE__PATH=/path/where/sqlite/dbs/are/stored
trytond-admin -d dbfilename -u moduletoupdate

```

This isn’t necessary it you modify just your python code.

### Execute the tryton server (trytond)

You can execute the tryton server with:

```bash
# with the configfile
trytond -c configfile.cfg

#with the enviroment variable
#export TRYTOND_DATABASE__PATH=/path/where/sqlite/dbs/are/stored
trytond

```

If you don’t want to reload the tryton server on every change, you can use the `--dev` flag.  
This flag will auto-reload your module every time tryton see a file-change in the trytond folder. If you created the simlink like above mentioned, trytond will reload changes every time you save your module. The command

```bash
#with the enviroment variable
#export TRYTOND_DATABASE__PATH=/path/where/sqlite/dbs/are/stored
trytond --dev

```

### the tryton client

You can install the tryton clinet via pip, the only caviat is that you need to install pygobject first..  
Thsi can be a problem inside a virtual enviroment, but just remember to install pygobject globally and make sure to create the virtualenviroment with the [system-site-packages](https://virtualenv.pypa.io/en/latest/reference/#cmdoption-system-site-packages) flag.

If you executed the tryton server locally, by default it will listen on 127.0.0.1:8000 (you can change it in the config file)  
When starting the client, you need to specify:

- host (127.0.0.1:8000 if the server is executed locally)
- database name (The databse nabe is the filename of the sqlite db you primed before)
- user (the only one is `admin` for the moment, the password is the one you inputted in the db priming stage)

### unit-testing

I suggest you read the guide here: [https://trytond.readthedocs.io/en/latest/topics/testing.html](https://trytond.readthedocs.io/en/latest/topics/testing.html)

---

_[View the full topic](https://discuss.tryton.org/t/how-to-setup-environment-to-create-a-new-module/1616)._
