Backend
This guide walks a developer through setting up a local development environment for the OCS Inventory Server Backend Rework repository - the Django-based rewrite of the OCS Inventory server backend.
This guide is for development environments only. For a production deployment, see the OCS Inventory Server Setup guide instead.
Overview
This repository contains only the backend (a Django REST API). It does not include the frontend SPA or the agent. To run a full stack locally, you'll also need the separate frontend project, but this guide only covers the backend.
Prerequisites
Python 3.12 or later - the project depends on
django>=6.0.2, which requires a recent Python version.pip (and optionally
venvorvirtualenv) - to manage dependencies in an isolated environment.Git - to clone the repository.
A database server - either PostgreSQL or MySQL/MariaDB. The project doesn't include a database setup script; you're expected to create the database and user yourself using your database system's own tools.
Build tools for
python-ldap(used for LDAP authentication). On Debian/Ubuntu, this typically means thelibldap2-dev,libsasl2-dev, andpython3-devsystem packages, plus a C compiler. See the python-ldap installation notes ifpip installfails on this dependency.
Step 1 - Clone the Repository
git clone https://github.com/OCSInventory-NG/OCSInventory-Server-Backend-Rework.git
cd OCSInventory-Server-Backend-ReworkThe default branch for active development is dev.
Step 2 - Create a Virtual Environment
Working in a virtual environment keeps this project's dependencies separate from your system's Python packages.
Step 3 - Install Python Dependencies
Install the base requirements first:
Then install the driver matching your database:
Step 4 - Create the Database
The project doesn't create the database or the database user for you. Using your database system's own tooling, create:
An empty database (e.g.
ocsinventory).A database user with full privileges on that database.
Refer to your database system's documentation for the exact commands (psql/createdb for PostgreSQL, mysql/mariadb client for MySQL/MariaDB).
Step 5 - Configure Environment Variables
Copy the sample environment file:
Edit .env with your own values:
DEBUG
True for a development environment (enables Django's debug mode). Keep False in production.
SECRET_KEY
Django's secret key. Replace the sample value with your own random string, even for local dev.
FRONTEND_REDIRECT
URL of the frontend application (e.g. http://localhost:3000), used for redirects after actions such as login.
DB_ENGINE
django.db.backends.postgresql for PostgreSQL, or django.db.backends.mysql for MySQL/MariaDB.
DB_NAME
Name of the database you created in Step 4.
DB_USER
Database user.
DB_PASSWORD
Database user's password.
DB_HOST
Database host (e.g. localhost).
DB_PORT
Database port (5432 for PostgreSQL, 3306 for MySQL/MariaDB).
For the full list of database options supported by Django, see the Django database documentation.
Step 6 - Apply Database Migrations
Once the database is reachable and .env is configured, create the schema:
Step 7 - Run the Development Server
By default, the API is now available at http://localhost:8000/. If you're running the frontend separately, make sure FRONTEND_REDIRECT in .env points to where the frontend is served.
Troubleshooting
pip install fails while building python-ldap
Missing system headers for LDAP/SASL. Install your OS's development packages and retry.
Django can't connect to the database
Check DB_HOST, DB_PORT, DB_USER, and DB_PASSWORD in .env, and confirm the database server is running and reachable.
Wrong database driver installed
Make sure DB_ENGINE in .env matches the requirements file you installed (requirements_psql.txt vs requirements_mysql.txt).
Frontend can't reach the API or redirects fail
Confirm FRONTEND_REDIRECT matches the actual URL where your frontend is running.
How to Contribute
Fork the repository on GitHub, then clone your fork locally (see the note in Step 1 above).
Create a branch for your change, based on main:
Make your changes, following the existing code style. The repository includes several quality and security configs (.cspell.json, .gitleaks.toml, .jscpd.json, .mega-linter.yml) — running the relevant checks locally before committing will catch most issues early and matches what CI checks on your pull request.
Commit and push your branch to your fork:
Open a pull request from your branch to the main branch of the main repository, with a clear description of what the change does and why.
One Last Thing
You made it through project installation, migrations and .env files without rage-quitting : you're basically already qualified.
OCS Inventory has been tracking IT assets since before some of your dependencies were born, and this backend rework is where the next chapter gets written. Every bug you squash, every endpoint you clean up, every typo you fix in a docstring makes life easier for the sysadmins out there who just want to know how many laptops still run an OS from a bygone era.
So go ahead, open that pull request. Worst case, a reviewer asks for changes. Best case, your code ships to inventory servers you'll never see, quietly doing its job for years. Either way, dev branch is waiting for you. 🚀
Last updated

