Skip to main content

SmartDoc: A tool to generate API documentation for FastAPI, Flask, and Django projects.

Project description

SmartDoc CLI

SmartDoc CLI is a command-line tool that automatically generates Markdown, HTML, and PDF API documentation for web frameworks like FastAPI, Flask, and Django.


Installation

pip install smartdoc-cli

(For testing with Test PyPI)

pip install --index-url https://test.pypi.org/simple/ smartdoc


Usage

Run this command inside your project directory.

Example command:

smartdoc generate \
  --app your_app.main \
  --framework fastapi \
  --output api_docs.md \
  --html \
  --pdf

For FastAPI:

smartdoc generate --app your_project.main --framework fastapi --output docs.md --html --pdf

For Flask:

smartdoc generate --app your_project.main --framework flask --output docs.md --html --pdf

For Django:

smartdoc generate --app your_project.main --framework django --django-settings your_project.settings --output docs.md --html --pdf

Troubleshooting SmartDoc

If running smartdoc generate causes import/module errors, follow these steps:

Common Error:

ModuleNotFoundError: No module named 'apps'

Fix:

# For Windows PowerShell
$env:PYTHONPATH="project"
smartdoc generate --app main --framework fastapi --output api_docs.md --html --pdf

Replace main with the filename (without .py) that runs your FastAPI app.

Checkpoint Description
PYTHONPATH set? Point to folder where apps/, main.py, etc. exist
Module correct? Use --app main not full path like project.main
Inside virtualenv? Make sure .venv is activated
Imports relative? Use from apps..., not project.apps...

Tip

If you want to avoid setting PYTHONPATH every time, create a PowerShell script run_smartdoc.ps1:

$env:PYTHONPATH="project"
smartdoc generate --app main --framework fastapi --output api_docs.md --html --pdf

smartdoc.json – Custom Configuration File

Place this in your root directory (same level as .venv, your_projects, etc.):

For FastApi

{
  "app": "main",
  "framework": "fastapi",
  "output": "api_docs.md",
  "html": true,
  "pdf": true,
  "pythonpath": "project_folder"
}

For Django

{
  "app": "project_name.urls",
  "framework": "django",
  "output": "api_docs.md",
  "html": true,
  "pdf": true,
  "pythonpath": "project_name",
  "django-settings": "project_name.settings"
}

For Flask

{
  "app": "app",  // path to your Flask app file (e.g. app.py without .py)
  "framework": "flask",
  "output": "api_docs.md",
  "html": true,
  "pdf": true,
  "pythonpath": "."
}

1. Then use a custom script to run it:

Here’s a reusable Python script (run_smartdoc.py) to load from this config:

run_smartdoc.py

import os
import subprocess
import json

with open("smartdoc.json") as f:
    config = json.load(f)

os.environ["PYTHONPATH"] = config["pythonpath"]

cmd = [
    "smartdoc",
    "generate",
    "--app", config["app"],
    "--framework", config["framework"],
    "--output", config["output"]
]

if config.get("html"):
    cmd.append("--html")
if config.get("pdf"):
    cmd.append("--pdf")

subprocess.run(cmd)

Run it with: python run_smartdoc.py

Note: Additional step for Django and Flask:

1. Django

In Python Script you need to set the DJANGO_SETTINGS_MODULE environment variable.

Update run_smartdoc.py like this:

os.environ["DJANGO_SETTINGS_MODULE"] = config.get("django-settings", "")

2. Flask

In flask you only have to give the path of .py file which contains `Flask(__name__)` in the place of app.

2. Makefile (For Mac/Linux or Git Bash)

If you're on Linux/macOS or using Git Bash on Windows, you can use a Makefile.

Makefile

PYTHONPATH=your-path

generate-docs:
	PYTHONPATH=$(PYTHONPATH) smartdoc generate \
		--app main \
		--framework fastapi \
		--output api_docs.md \
		--html \
		--pdf

Run it with: make generate-docs

NOTE: Make the necessary changes for Django and Flask



CLI Options

Option Description
--app / -a Python path to your app module
--framework / -f One of fastapi, flask, django
--output / -o Output Markdown filename (default: api_docs.md)
--html Generate HTML output
--pdf Generate PDF output
--django-settings Required for Django to specify settings module

Output

Depending on options used:

api_docs.md — default markdown output

api_docs.html — HTML format (with --html)

api_docs.pdf — PDF format (with --pdf)


Author

Built with 💻 by Mohammad Safwan Athar @DevSaifOps


License

This project is licensed under the MIT License.


MIT License

Copyright (c) 2025 Mohammad Safwan Athar aka DevSaifOps

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

smartdoc_cli-0.1.3.tar.gz (9.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

smartdoc_cli-0.1.3-py3-none-any.whl (10.2 kB view details)

Uploaded Python 3

File details

Details for the file smartdoc_cli-0.1.3.tar.gz.

File metadata

  • Download URL: smartdoc_cli-0.1.3.tar.gz
  • Upload date:
  • Size: 9.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.4

File hashes

Hashes for smartdoc_cli-0.1.3.tar.gz
Algorithm Hash digest
SHA256 7a8f4e360b5e857423d9ba4a51bfb7ba164dcc2642f2f3c551cf0e3fc0099584
MD5 21e59b7dee9c1923879899cac0a6dbd1
BLAKE2b-256 0b2a5436a5470836df09b10c0b5f439ce8cce05ed51bdd816eaac8666f602ed5

See more details on using hashes here.

File details

Details for the file smartdoc_cli-0.1.3-py3-none-any.whl.

File metadata

  • Download URL: smartdoc_cli-0.1.3-py3-none-any.whl
  • Upload date:
  • Size: 10.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.4

File hashes

Hashes for smartdoc_cli-0.1.3-py3-none-any.whl
Algorithm Hash digest
SHA256 5af267d0e7673995ec9e59d06d2e0768dc139baf55329786a26fa8dd35733e36
MD5 6701f906d0ade468adab1d1303d056ca
BLAKE2b-256 11f776d2eedc8221b6fc3d4684d738ab76ba33e0c781fdda2259ce843692bed4

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page