Skip to main content

Numbat

Numbat is an API to create and manipulate Sourcetrail databases. Sourcetrail is a code source explorer which allows users to navigate through the different components (functions, classes, types, etc.) easily.

Numbat main goal is to offer a full-python SDK given the fact that the current one, SourcetrailDB cannot be used anymore efficiently. It is not user-friendly at first sight, need to be compiled to provide Python bindings and, moreover, it is no longer maintained. Finally, we have added some little new features as finding an element in the database.

With Numbat, you will be able to visualize your data quickly with the nice graphical Sourcetrail interface. For example, Pyrrha uses Numbat to map firmware structure.

Installation

Numbat is available on pypi.

pip install numbat

From sources

You can also install it from the git repository. Either using the following oneliner:

pip install 'numbat @ git+https://github.com/quarkslab/numbat'

or doing it in few steps:

# Download the repo
git clone https://gitlab.qb/firmware-re/cartography/numbat
cd numbat
# Install numbat locally
pip install .

Build Documentation

If you want to build the documentation by first installing Numbat with the required [doc] dependencies and then serve the documentation on a local server.

# if you already have a local clone of the project
cd NUMBAT_DIR
pip install .[doc]

# otherwise
pip install 'numbat[doc]'

# serve doc locally
mkdocs serve

Basic Usage

A complete usage with examples is available in the documentation but here is a quick usage to begin with Numbat.

To use Numbat, you must first create a SourcetrailDB object and either create a new database or open an existing one:

from pathlib import Path
from numbat import SourcetrailDB

db_path = Path('my_database')
try:
    # Create a new database
    srctrl = SourcetrailDB.create(db_path)
except FileExistsError:
    # Database already exists, open it and remove the entire content with clear
    srctrl = SourcetrailDB.open(db_path)
    srctrl.clear()

You could also use this one-liner to open the database quicker:

from pathlib import Path
from numbat import SourcetrailDB

srctrl = SourcetrailDB.open(Path('my_database'), clear=True)

Once the database is open, you can add one or more source files in the database using the following snippet:

file_id = srctrl.record_file(Path('my_file.c'))
srctrl.record_file_language(file_id, 'C')

To populate the database, it is possible to record different symbols such as class or function like this:

symbol_id = srctrl.record_class(name="MyClass", is_indexed=True)
# if you have a source code, you can add the location of your symbol definition
srctrl.record_symbol_location(symbol_id, file_id, 2, 7, 2, 12)
# and your symbol scope
srctrl.record_symbol_scope_location(symbol_id, file_id, 2, 1, 7, 1)

Once the database is filled with information, it must be saved and close like this:

srctrl.commit()
srctrl.close()

Authors

  • Sami Babigeon (@sbabigeon), Quarkslab
  • Eloïse Brocas (@ebrocas), Quarkslab

The logo is a creation of Benoît Forgette and Sami Babigeon.

Metadata

Release files for numbat 0.2.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for numbat 0.2.0
File Size Uploaded
numbat-0.2.0.tar.gz 762.3 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for numbat 0.2.0
File Interpreter ABI Platform
numbat-0.2.0-py3-none-any.whl Python 3 none any Details

Total release size: 788.6 kB

Release files / numbat-0.2.0.tar.gz

Download URL numbat-0.2.0.tar.gz
Size 762.3 kB
Tags Source
SHA-256 checksum
How to use checksums
5e0c54369a5e6490db4929e00238f12b2cf7a0ca60f4ac5f15f523db02b5eefe
BLAKE2b-256 checksum
How to use checksums
77eaf259e7ed6b5fec20734578d885ba64c4960aa7e839044a7664f92f1f1790
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.1 CPython/3.11.7

Release files / numbat-0.2.0-py3-none-any.whl

Download URL numbat-0.2.0-py3-none-any.whl
Size 26.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
875e520dd2cde3172c609d41348fa6642ca95aa57f2940ce67a26327cb5f6db9
BLAKE2b-256 checksum
How to use checksums
0319ecebf70515c530d89d0e202036db9642bd21bcb2a0e2a32f68df9ae15c6c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.1 CPython/3.11.7

Release history Release notifications | RSS feed

0.2.7

2 release files

0.2.6

2 release files

0.2.5

2 release files

0.2.4

2 release files

0.2.3

2 release files

0.2.2

2 release files

0.2.1

2 release files

This release

0.2.0 This release

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page