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.4.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.4-py3-none-any.whl (10.2 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: smartdoc_cli-0.1.4.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.4.tar.gz
Algorithm Hash digest
SHA256 e1a52fc337867f75b4a78d8e5cd260ebd6096f83366cb3643d369ed82817de76
MD5 ac707b473911c4e264a667648c0cc960
BLAKE2b-256 db33e35c0479b86faf74cc2b1c479b64f15da10fe135f78fa9e6c844c3a869ef

See more details on using hashes here.

File details

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

File metadata

  • Download URL: smartdoc_cli-0.1.4-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.4-py3-none-any.whl
Algorithm Hash digest
SHA256 8f6e396bed8aeac2e96c58cd5e78745646f22f966494d32199634bb258b1d257
MD5 d4e969bb93db4192f51b38182810204f
BLAKE2b-256 78be8c27dd4faed4dc2e52fc4dd4511312722b8b8d44428daea2e21d12f08dde

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