Metadata-Version: 2.5
Name: drf-diag-utils-wip
Version: 0.1.0
Summary: Work in progress: read-only startup diagnostics for Django and Django REST framework services.
Author: Zahari Petkov
License-Expression: MIT
License-File: LICENSE
Keywords: diagnostics,django,djangorestframework
Classifier: Development Status :: 2 - Pre-Alpha
Classifier: Framework :: Django
Classifier: Intended Audience :: Developers
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.12
Classifier: Typing :: Typed
Requires-Python: >=3.12
Requires-Dist: django>=5.2
Provides-Extra: drf
Requires-Dist: djangorestframework>=3.16; extra == 'drf'
Description-Content-Type: text/markdown

# drf-diag-utils-wip

Read-only startup diagnostics for Django and Django REST framework services.

> **Work in progress.** This package is permanently pre-release: its API and output may change in any version. Pin an exact version if you depend on it.

`collect()` returns a list of entries describing the running service. `print_diagnostics()` writes them to the console. Nothing is written, no database connection is opened and no network call is made, so it is safe to run at startup in any environment.

## Install

```bash
pip install "drf-diag-utils-wip[drf]"   # the [drf] extra enables the endpoint and API sections
```

## Use

Call it once Django is set up, for example from a management command or a provisioning step:

```python
from drf_diag_utils import collect, print_diagnostics

print_diagnostics()

for entry in collect():  # or log the entries yourself
    logger.info("%s: %s = %s", entry.section, entry.label, entry.value)
```

Output, for the small project in `tests/`:

```text
[runtime]
  Python                 3.12.13
  Django                 6.1.2
  Django REST framework  3.18.3
  Settings module        tests.settings
  DEBUG                  False

[apps]
  tests.demo        Demo
  third-party apps  3

[endpoints]
  /api/ping/    GET  (PingView)
  /items/       GET POST  (ItemViewSet)
  /items/{pk}/  GET  (ItemViewSet)
  total         3

[api defaults]
  authentication  rest_framework.authentication.SessionAuthentication, rest_framework.authentication.BasicAuthentication
  permissions     rest_framework.permissions.IsAuthenticated
  pagination      rest_framework.pagination.PageNumberPagination
  page size       25

[databases]
  default  django.db.backends.sqlite3

[checks]
  errors    0
  warnings  0
```

## Sections

| Section | Shows |
| --- | --- |
| runtime | Python, Django and DRF versions, the settings module, `DEBUG` |
| apps | The project's own apps (under `BASE_DIR`, or outside the installed packages), then a count of third-party apps |
| endpoints | Every DRF endpoint with its methods and view, as DRF's schema generation enumerates them |
| api defaults | Default authentication, permission and pagination classes, and the page size |
| databases | The engine of each database alias - never its host, name or credentials |
| checks | The number of system-check errors and warnings, and each error |

A section that fails appears as an `error` entry instead of raising, so the diagnostics can never stop a service from starting.

## Develop

```bash
uv sync
uv run pytest
uv run ruff check .
uv build
```

## License

MIT - see [LICENSE](LICENSE).
