Skip to content

booklab">

booklab

booklab main python package for Booklab system

Consists of the following sub-packages:

  • booklab-cli which is a CLI application to manage system
  • booklabd designed to serve /api/.../ system routes that need database write access
  • conf containing configuration files for different system components including infrastructure ones like gunicorn or nginx
  • doc_src contains the source of static site directory as Markdown files
  • docs/ contains rhe static site compiled and "ready to use as-is" with any standard HTTP server
  • doc-techical containing system usage documentation (aka api interface)
  • my_books contains the end user created & generated books and books_catalog.json with info about all user books

  • scripts/ contains various scrpts usefull in system administrarion (install, maintain, confifure, etc)

Author: Petre Iordanescu (petre.iordanescu@gmail.com)

booklab.booklab_cli

Booklab CLI module to assure system operatins as command line.

Usage:

booklab -v
booklab setup <options>
booklab init <options>
booklab server (run|stop|restart)
booklab book (new|build|preview|deploy|edit)
booklab catalog [book] <-ls>

Options:

-l, --list    List books catalog
-s, --status  Display detailes about a book
-v, --version Display booklab application version

Architecture; Linux standard (POSIX) CLI

Author; Petre Iordanescu (petre.iordanescu@gmail.com)

booklab.conf

Cnfigurations component contains various system components configuration files:

  • gunicorn WSGI web server
  • nginx local proxy HTTP

Notes / remarks:

  • files wirh .py extension are considered Python files and can be imported accordingly as longas they are valid Python-code.
  • all files from here are assumed to be text files. Any deviation from this rule is assumed to be treated accordingly in code.

Author; Petre Iordanescu (petre.iordanescu@gmail.com)

booklab.conf.gunicorn_config

Configuration file for gunicorn in serving booklabd server application

This is a Python file that will be executed by gunicorn at run-time. As consequence declare all assignements as valid Python code.

Author: Petre Iordanescu (petre.iordanescu@gmail.com)

booklab.conf.booklab_ext_url

This Python file contains external access URL information. By external access is understood all URL parts necessary to expose Booklab application:

  • EXT_SERVER - the external exposed server name and port if diffrent than standard default (80 or 443) (example: "booklab.mydomain.ro")
  • EXT_PATH - the external exposed URL of configured start locations through a LAN main proxy (example: "/booklab/" for a complete external URL like http://booklab.mydomain.ro:5002/booklab/)

NOTE: all information are of string type

Author: Petre Iordanescu (petre.iordanescu@gmail.com)

booklab.my_books.book_template

Contains the book template used when create a new book (newb funxtion, /api/newb/ booklabd route).

Author: Petre Iordanescu (petre.iordanescu@gmail.com)

booklab.my_books

This component contains all defined books as individual directories, each one with all definions initiated from book_template/ directory

Author: Petre Iordanescu (petre.iordanescu@gmail.com)

booklab.my_books.books_manager

MyBook Objects

class MyBook()

Class that manage end user books.

Important properties:

  • MY_BOOK_URL: url to redirect to access book static site (preview book)
  • MY_BOOK_PATH: file-parh to book root location

Author: Petre Iordanescu (petre.iordanescu@gmail.com)

__init__

def __init__(flask_app: Flask, db: pysondb, book_code: str)

Init an instance of class MyBook

getBook

def getBook() -> dict | None

Check for a given book code that is not None, exists in database and is exactly 1 record

Returns:

  • dict with found record or None if any of conditiona is not met

getBookPath

def getBookPath() -> str

Get absolute path of current book root directory.

getBookURL

def getBookURL() -> str

Get preview URL (redirectable as is) for current book_code.

renderBookConfig

def renderBookConfig(out_file: str = "mkdocs.yml") -> bool

Render current book configuration file used in static site generation.

booklab.doc_src

Booklab master static site:

  • doc_src/ markdown source files
  • docs/ generated static site ready to be used as is with any standard HTTP server

Author: Petre Iordanescu (petre.iordanescu@gmail.com)

booklab.scripts

Booklab utility scripts that solve various aspects in installing, configuring and running Booklab system / application.

Author: Petre Iordanescu (petre.iordanescu@gmail.com)

booklab.__version__

version.py module that contains Booklab aplication version number.

NOTE: this module is imported and made "public" in booklab._init__.py

Author: Petre Iordanescu (petre.iordanescu@gmail.com)

booklab.booklabd.routes

Module that serve booklabd interface api-functions as HTTP routes

Important variables:

  • booklab.boolabd.api_app: web application object (aka Flask.app)

Author: Petre Iordanescu (petre.iordanescu@gmail.com)

api_newb

@api_app.route("/api/newb/")
def api_newb()

serve New book (newb) functionality.

Query paraneters: none

api_bstatus

@api_app.route("/api/bstatus/")
def api_bstatus(book_code=...)

serve Book status (bstatus) functionality.

Query paraneters: book code

api_edtb

@api_app.route("/api/edtb/")
def api_edtb(book_code=...)

serve Book edit (edtb) functionality.

Query paraneters: book code

api_orgm

@api_app.route("/api/orgm/")
def api_orgm(book_code=...)

serve Book structure organization (orgm: functionality.

Query paraneters: book code

api_prvb

@api_app.route("/api/prvb/")
def api_prvb(book_code=...)

serve Book preview (prvb) functionality.

Query paraneters: book code

api_bbld

@api_app.route("/api/bbld/")
def api_bbld(book_code=...)

serve Book build (bbld) functionality.

Query paraneters: book code

api_dplb

@api_app.route("/api/dplb/")
def api_dplb(book_code=...)

serve Book delivery (dplb) functionality.

Query paraneters: book code

api_bcat

@api_app.route("/api/bcat/")
def api_bcat()

serve accessing books catalog (bcat) functionality.

index

@api_app.route("/")
def index()

serve a cessing Home route. This is an alternate (but those expected from an end user) way to access static site main / home page.

booklab.booklabd.app_init

app_init module that initialize booklabd application

This module is designed to initialize the main web application object api_app.

Author: Petre Iordanescu (petre.iordanescu@gmail.com)

init_app

def init_app(app_name: str, static_site_dir: str, templates_dir: str,
             pjroot_location: str) -> Flask

Create Flask application object and return it

Arguments:

  • app_name - name of web application objwcr
  • static_site_dir - directory used by Flask app to render Jinja templates
  • templates_dir - directory name where templates are to becfound (relative to pjroot_location)
  • pjroot_location - project root directory (relative to pjroot_location)

Returns:

web application object

booklab.booklabd

booklabd - Booklab API server module

Main functionalities: * operate & manage JSON database file * provide necessary http API routes fir book functionalities that need write & dynamic (run-time) behavior

Architecture; HTTP WSGI

Author: Petre Iordanescu (petre.iordanescu@gmail.com)

booklab.docs

Booklab master static site:

  • doc_src/ markdown source files
  • docs/ generated static site ready to be used as is with any standard HTTP server

Author: Petre Iordanescu (petre.iordanescu@gmail.com)

booklab..venv.lib.python3.10.site-packages._virtualenv

Patches that are applied at runtime to the virtual environment.

patch_dist

def patch_dist(dist)

Distutils allows user to configure some arguments via a configuration file: https://docs.python.org/3/install/index.html#distutils-configuration-files.

Some of this arguments though don't make sense in context of the virtual environment files, let's fix them up.

_Finder Objects

class _Finder()

A meta path finder that allows patching the imported distutils modules.

lock

noqa: RUF012

booklab..venv.bin.activate_this

Activate virtualenv for current interpreter:

import runpy runpy.run_path(this_file)

This can be used when you must use an existing Python interpreter, not the virtualenv bin/python.

base

strip away the bin part from the file, plus the path separator

booklab.__main__

... wip ... modules to be launched at package call with -m option

booklab.db_init

Module that initialize booklabd database (more JSON files)

This module is designed to initialize database objects db_books and db_system.

Author: Petre Iordanescu (petre.iordanescu@gmail.com)

init_db

def init_db() -> tuple[pysondb]

Create db_books, db_system objects and return them as tuple

Returns:

(db_books, db_system) tuple of pysondb object


Last update: October 14, 2025