Generate markdown API docs with griffe

- scripts/generate_docs.py: Generate .md files from docstrings
- docs/api/*.md: Auto-generated API documentation
- Pre-commit hook: Auto-generate markdown on commit
- Uses griffe AST parser (no code execution)

Generated files:
- docs/api/index.md
- docs/api/kworkclient.md
- docs/api/client/*.md
- docs/api/models/*.md
- docs/api/errors/*.md
This commit is contained in:
root 2026-03-23 03:52:07 +00:00
parent 080e5ddc72
commit f7ab02d3cf
63 changed files with 467 additions and 0 deletions

View File

@ -0,0 +1,3 @@
# APIErrorResponse
Standard API error response.

View File

@ -0,0 +1,3 @@
# AuthResponse
Authentication response.

3
docs/api/client/badge.md Normal file
View File

@ -0,0 +1,3 @@
# Badge
User badge information.

View File

@ -0,0 +1,3 @@
# CatalogResponse
Catalog response with kworks and pagination.

3
docs/api/client/city.md Normal file
View File

@ -0,0 +1,3 @@
# City
City information.

View File

@ -0,0 +1,3 @@
# Country
Country information.

View File

@ -0,0 +1,3 @@
# DataResponse
Generic data response wrapper.

View File

@ -0,0 +1,3 @@
# Dialog
Dialog (chat) information.

View File

@ -0,0 +1,3 @@
# Feature
Feature/addon information.

33
docs/api/client/index.md Normal file
View File

@ -0,0 +1,33 @@
# client
Kwork API Client.
Main client class with authentication and all API endpoints.
## Classes
- [KworkApiError](kworkapierror.md)
- [KworkAuthError](kworkautherror.md)
- [KworkError](kworkerror.md)
- [KworkNetworkError](kworknetworkerror.md)
- [KworkNotFoundError](kworknotfounderror.md)
- [KworkRateLimitError](kworkratelimiterror.md)
- [KworkValidationError](kworkvalidationerror.md)
- [APIErrorResponse](apierrorresponse.md)
- [AuthResponse](authresponse.md)
- [Badge](badge.md)
- [CatalogResponse](catalogresponse.md)
- [City](city.md)
- [Country](country.md)
- [DataResponse](dataresponse.md)
- [Dialog](dialog.md)
- [Feature](feature.md)
- [Kwork](kwork.md)
- [KworkDetails](kworkdetails.md)
- [NotificationsResponse](notificationsresponse.md)
- [Project](project.md)
- [ProjectsResponse](projectsresponse.md)
- [Review](review.md)
- [ReviewsResponse](reviewsresponse.md)
- [TimeZone](timezone.md)
- [KworkClient](kworkclient.md)

3
docs/api/client/kwork.md Normal file
View File

@ -0,0 +1,3 @@
# Kwork
Kwork (service) information.

View File

@ -0,0 +1,3 @@
# KworkApiError
API request error (4xx, 5xx).

View File

@ -0,0 +1,3 @@
# KworkAuthError
Authentication/authorization error.

View File

@ -0,0 +1,36 @@
# KworkClient
Kwork.ru API client.
Usage:
# Login with credentials
client = await KworkClient.login("username", "password")
# Or restore from token
client = KworkClient(token="your_web_auth_token")
# Make requests
catalog = await client.catalog.get_list(page=1)
## Methods
### `login(username: str, password: str, timeout: float = 30.0)`
Login with username and password.
Args:
username: Kwork username or email
password: Kwork password
timeout: Request timeout
Returns:
Authenticated KworkClient instance
Raises:
KworkAuthError: If login fails
### `close()`
Close HTTP client.

View File

@ -0,0 +1,3 @@
# KworkDetails
Extended kwork details.

View File

@ -0,0 +1,3 @@
# KworkError
Base exception for all Kwork API errors.

View File

@ -0,0 +1,3 @@
# KworkNetworkError
Network/connection error.

View File

@ -0,0 +1,3 @@
# KworkNotFoundError
Resource not found (404).

View File

@ -0,0 +1,3 @@
# KworkRateLimitError
Rate limit exceeded (429).

View File

@ -0,0 +1,3 @@
# KworkValidationError
Validation error (400).

View File

@ -0,0 +1,3 @@
# NotificationsResponse
Notifications list response.

View File

@ -0,0 +1,3 @@
# Project
Project (freelance order) information.

View File

@ -0,0 +1,3 @@
# ProjectsResponse
Projects list response.

View File

@ -0,0 +1,3 @@
# Review
Review information.

View File

@ -0,0 +1,3 @@
# ReviewsResponse
Reviews list response.

View File

@ -0,0 +1,3 @@
# TimeZone
Timezone information.

15
docs/api/errors/index.md Normal file
View File

@ -0,0 +1,15 @@
# errors
Kwork API exceptions.
All exceptions provide clear error messages for debugging.
## Classes
- [KworkError](kworkerror.md)
- [KworkAuthError](kworkautherror.md)
- [KworkApiError](kworkapierror.md)
- [KworkNotFoundError](kworknotfounderror.md)
- [KworkRateLimitError](kworkratelimiterror.md)
- [KworkValidationError](kworkvalidationerror.md)
- [KworkNetworkError](kworknetworkerror.md)

View File

@ -0,0 +1,3 @@
# KworkApiError
API request error (4xx, 5xx).

View File

@ -0,0 +1,3 @@
# KworkAuthError
Authentication/authorization error.

View File

@ -0,0 +1,3 @@
# KworkError
Base exception for all Kwork API errors.

View File

@ -0,0 +1,3 @@
# KworkNetworkError
Network/connection error.

View File

@ -0,0 +1,3 @@
# KworkNotFoundError
Resource not found (404).

View File

@ -0,0 +1,3 @@
# KworkRateLimitError
Rate limit exceeded (429).

View File

@ -0,0 +1,3 @@
# KworkValidationError
Validation error (400).

24
docs/api/index.md Normal file
View File

@ -0,0 +1,24 @@
# kwork_api
Kwork.ru API Client
Unofficial Python client for Kwork.ru API.
Example:
from kwork_api import KworkClient
# Login with credentials
client = await KworkClient.login("username", "password")
# Or restore from token
client = KworkClient(token="your_web_auth_token")
# Get catalog
catalog = await client.catalog.get_list(page=1)
## Classes
- [KworkClient](kworkclient.md)
- [KworkError](kworkerror.md)
- [KworkAuthError](kworkautherror.md)
- [KworkApiError](kworkapierror.md)

View File

@ -0,0 +1,3 @@
# KworkApiError
API request error (4xx, 5xx).

View File

@ -0,0 +1,3 @@
# KworkAuthError
Authentication/authorization error.

36
docs/api/kworkclient.md Normal file
View File

@ -0,0 +1,36 @@
# KworkClient
Kwork.ru API client.
Usage:
# Login with credentials
client = await KworkClient.login("username", "password")
# Or restore from token
client = KworkClient(token="your_web_auth_token")
# Make requests
catalog = await client.catalog.get_list(page=1)
## Methods
### `login(username: str, password: str, timeout: float = 30.0)`
Login with username and password.
Args:
username: Kwork username or email
password: Kwork password
timeout: Request timeout
Returns:
Authenticated KworkClient instance
Raises:
KworkAuthError: If login fails
### `close()`
Close HTTP client.

3
docs/api/kworkerror.md Normal file
View File

@ -0,0 +1,3 @@
# KworkError
Base exception for all Kwork API errors.

View File

@ -0,0 +1,3 @@
# APIErrorResponse
Standard API error response.

View File

@ -0,0 +1,3 @@
# AuthResponse
Authentication response.

3
docs/api/models/badge.md Normal file
View File

@ -0,0 +1,3 @@
# Badge
User badge information.

View File

@ -0,0 +1,3 @@
# CatalogResponse
Catalog response with kworks and pagination.

3
docs/api/models/city.md Normal file
View File

@ -0,0 +1,3 @@
# City
City information.

View File

@ -0,0 +1,3 @@
# Country
Country information.

View File

@ -0,0 +1,3 @@
# DataResponse
Generic data response wrapper.

View File

@ -0,0 +1,3 @@
# Dialog
Dialog (chat) information.

View File

@ -0,0 +1,3 @@
# ErrorDetail
Error detail from API.

View File

@ -0,0 +1,3 @@
# Feature
Feature/addon information.

30
docs/api/models/index.md Normal file
View File

@ -0,0 +1,30 @@
# models
Pydantic models for Kwork API responses.
All models follow the structure found in the HAR dump analysis.
## Classes
- [KworkUser](kworkuser.md)
- [KworkCategory](kworkcategory.md)
- [Kwork](kwork.md)
- [KworkDetails](kworkdetails.md)
- [PaginationInfo](paginationinfo.md)
- [CatalogResponse](catalogresponse.md)
- [Project](project.md)
- [ProjectsResponse](projectsresponse.md)
- [Review](review.md)
- [ReviewsResponse](reviewsresponse.md)
- [Notification](notification.md)
- [NotificationsResponse](notificationsresponse.md)
- [Dialog](dialog.md)
- [AuthResponse](authresponse.md)
- [ErrorDetail](errordetail.md)
- [APIErrorResponse](apierrorresponse.md)
- [City](city.md)
- [Country](country.md)
- [TimeZone](timezone.md)
- [Feature](feature.md)
- [Badge](badge.md)
- [DataResponse](dataresponse.md)

3
docs/api/models/kwork.md Normal file
View File

@ -0,0 +1,3 @@
# Kwork
Kwork (service) information.

View File

@ -0,0 +1,3 @@
# KworkCategory
Category information.

View File

@ -0,0 +1,3 @@
# KworkDetails
Extended kwork details.

View File

@ -0,0 +1,3 @@
# KworkUser
User information.

View File

@ -0,0 +1,3 @@
# Notification
Notification information.

View File

@ -0,0 +1,3 @@
# NotificationsResponse
Notifications list response.

View File

@ -0,0 +1,3 @@
# PaginationInfo
Pagination metadata.

View File

@ -0,0 +1,3 @@
# Project
Project (freelance order) information.

View File

@ -0,0 +1,3 @@
# ProjectsResponse
Projects list response.

View File

@ -0,0 +1,3 @@
# Review
Review information.

View File

@ -0,0 +1,3 @@
# ReviewsResponse
Reviews list response.

View File

@ -0,0 +1,3 @@
# TimeZone
Timezone information.

125
scripts/generate_docs.py Normal file
View File

@ -0,0 +1,125 @@
#!/usr/bin/env python3
"""
Generate Markdown API documentation using griffe.
Usage:
python scripts/generate_docs.py
Generates docs/api/*.md from source code docstrings.
"""
import sys
from pathlib import Path
from griffe import GriffeLoader, ObjectKind
def format_signature(obj):
"""Format object signature."""
params = []
for param in obj.parameters:
if param.name in ("self", "cls"):
continue
p = param.name
if param.annotation:
p += f": {param.annotation}"
if param.default:
p += f" = {param.default}"
params.append(p)
return f"({', '.join(params)})"
def generate_class_md(cls, output_path: Path):
"""Generate markdown for a class."""
lines = [
f"# {cls.name}",
"",
cls.docstring.value if cls.docstring else "",
"",
]
# Methods
methods = [m for m in cls.members.values() if m.kind == ObjectKind.FUNCTION and not m.name.startswith("_")]
if methods:
lines.append("## Methods")
lines.append("")
for method in methods:
sig = format_signature(method)
lines.append(f"### `{method.name}{sig}`")
lines.append("")
if method.docstring:
lines.append(method.docstring.value)
lines.append("")
lines.append("")
output_path.write_text("\n".join(lines))
def generate_module_md(module, output_dir: Path):
"""Generate markdown files for a module."""
output_dir.mkdir(parents=True, exist_ok=True)
# Generate index for module
index_path = output_dir / "index.md"
lines = [
f"# {module.name}",
"",
module.docstring.value if module.docstring else "",
"",
"## Classes",
"",
]
for name, obj in module.members.items():
if obj.kind == ObjectKind.CLASS and not name.startswith("_"):
lines.append(f"- [{name}]({name.lower()}.md)")
# Generate class file
class_path = output_dir / f"{name.lower()}.md"
generate_class_md(obj, class_path)
lines.append("")
index_path.write_text("\n".join(lines))
def main():
"""Main entry point."""
root_dir = Path(__file__).parent.parent
src_dir = root_dir / "src" / "kwork_api"
docs_dir = root_dir / "docs" / "api"
if not src_dir.exists():
print(f"❌ Source directory not found: {src_dir}")
sys.exit(1)
print("📝 Loading source code with griffe...")
# Load with griffe (AST parsing, no code execution)
loader = GriffeLoader(search_paths=[src_dir.parent])
module = loader.load("kwork_api")
print("📄 Generating markdown documentation...")
# Generate for main modules
generate_module_md(module, docs_dir)
# Generate client.md
if "client" in module.members:
generate_module_md(module["client"], docs_dir / "client")
# Generate models.md
if "models" in module.members:
generate_module_md(module["models"], docs_dir / "models")
# Generate errors.md
if "errors" in module.members:
generate_module_md(module["errors"], docs_dir / "errors")
print(f"✅ Generated markdown in {docs_dir}")
if __name__ == "__main__":
main()