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.5.tar.gz (10.4 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.5-py3-none-any.whl (10.6 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: smartdoc_cli-0.1.5.tar.gz
  • Upload date:
  • Size: 10.4 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.5.tar.gz
Algorithm Hash digest
SHA256 4d3941be563c14b162c767c875c0323e6a68287ae83c5106327a0ec3d0897cd7
MD5 1aebbc81d6b685b47d666a14edc17963
BLAKE2b-256 cb7983a62a1bb4cf0370694d9c0843221ea6831efe17a9fc1eb80fecc10fa546

See more details on using hashes here.

File details

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

File metadata

  • Download URL: smartdoc_cli-0.1.5-py3-none-any.whl
  • Upload date:
  • Size: 10.6 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.5-py3-none-any.whl
Algorithm Hash digest
SHA256 ee76d9bda408e999b01ad0f615df4ad9eb16c3fb54dc7308936db15824b62a0a
MD5 e2fb194a3406c27bfb77c301b3e9f07d
BLAKE2b-256 0c279bc2bf18ac5091eb3cb1481da8465cc1840633330b139369c9eb33343b5e

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