This is repo for the backend API for the digital register page
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.


This is the repo for the backend of the digital register service. It is written in Python, with the Flask framework.

Digital Register API build status

Build Status

Digital Register Acceptance tests status

Build Status


To create a virtual env, run the following from a shell:

    mkvirtualenv -p /usr/bin/python3 digital-register-api
    pip install -r requirements.txt

Run unit tests

To run unit tests for the Digital Register, go to its folder and run lr-run-tests.

Run integration tests

In order to run Digital Register API integration tests, go to its folder and run ./ This script creates the test database (test_register_data) and test elasticsearch index (test-landregistry) and runs the tests against them. Make sure you have postgresql and elasticsearch services running (by executing the lr-start-services command).

Run the acceptance tests

To run the acceptance tests for the Digital Register, go to the acceptance-tests folder inside the digital-register-frontend repository and run:


You will need to have a Postgres database running (see db/lr-start-db and db/insert-fake-data scripts in the centos-dev-env project), as well as the digital-register-frontend and digital-register-api applications running on your development VM.

Run the server

Run in dev mode

To run the server in dev mode, execute the following command:


Run using gunicorn

To run the server using gunicorn, activate your virtual environment and execute the following commands:

pip install gunicorn
gunicorn -p /tmp/ service.server:app -c 

Jenkins builds

We use three separate builds:

Database migrations

We use Flask-Migrate (a project which integrates Flask with Alembic, a migration tool from the author of SQLAlchemy) to handle database migrations. Every time a model is added or modified, a migration script should be created and committed to our version control system.

From inside a virtual environment, and after sourcing, run the following to add a new migration script:

python3 db migrate -m "add foobar field"

Should you ever need to write a migration script from scratch (to migrate data for instance) you should use the revision command instead of migrate:

python3 db revision -m "do something complicated"

Read Alembic's documentation to learn more.

Once you have a migration script, the next step is to apply it to the database. To do this run the upgrade command:

python3 db upgrade

Populate the mapping table

Once you have the new uprn_mapping table, you may want to have some data in it. Assume you have created and working on the digital-register-api virtual environment:

python3 -file path/to/file.csv

Some useful operators:

-f path/to/file.csv This will import a CSV file.
-s <number>         This will start the file read from <number>. Handy if the import stopped half way through a million records and you need to start again around 500000.
-o                  This will delete and replace any existing entries
-c                  This will clear the whole table and start again