Skip to main content

baltimore-patapsco (Python)

Reusable Django runtime primitives for Baltimore civic applications.

INSTALLED_APPS += ["baltimore.patapsco"]

REST_FRAMEWORK = {
    "EXCEPTION_HANDLER": "baltimore.patapsco.api.exception_handler",
}

urlpatterns = [path("", include("baltimore.patapsco.urls"))]

Place RequestContextMiddleware early in MIDDLEWARE — after SecurityMiddleware (and WhiteNoise when present), before session, auth, and anything that can short-circuit a response — so every later middleware, view, and log line sees the bound request ID. The reference app shows the canonical order:

MIDDLEWARE = [
    "django.middleware.security.SecurityMiddleware",
    "whitenoise.middleware.WhiteNoiseMiddleware",
    "baltimore.patapsco.observability.RequestContextMiddleware",
    # sessions, common, csrf, auth, messages, clickjacking...
]

Stable health and readiness views

Applications that mount or extend the operational views directly use the public facade:

from baltimore.patapsco.api import HealthView, ReadinessView

HealthView is process-only liveness. ReadinessView runs the established database check and returns its public-safe 200 or 503 status document. Both use no authentication classes and AllowAny, and both remain ordinary DRF APIView classes with as_view().

An application may subclass either class, override get(), and call super().get(request) before composing app-owned public-safe checks. The parent response status, request ID, and database result remain the starting contract; the application owns an explicit serializer and OpenAPI annotation for any extended payload.

The previous baltimore.patapsco.api.views imports resolve to the same class objects for compatibility. DiagnosticsView remains available only from that module and through the packaged URL configuration; it is intentionally absent from baltimore.patapsco.api.__all__ because its staff/public policy is a separate operational surface. The settings-free package root exports neither view class.

api_error_response() and the DRF exception handler force every 5xx response to the public internal_error code, generic message, and no details. Application callers cannot opt a server failure out of that safety boundary.

Use build_logging_config() for the shared JSON/pretty log shape. Modules are incrementally adoptable; installing the package does not enable auth, email, or Sentry by itself.

Sentry privacy defaults

Install the observability extra and call the shared initializer only when a DSN is configured:

from baltimore.patapsco.observability import configure_sentry

configure_sentry(
    environment="production",
    release="my-app@1.2.3",
    traces_sample_rate=0.1,
)

configure_sentry() is deny-by-default: it disables automatic PII, request-body capture, and stack-frame local variables. Its event pipeline also removes request cookies and query strings, strips query/fragment data from request URLs, and recursively redacts Sentry's credential/session denylist plus common civic contact and precise-location fields. Safe operational fields such as request IDs, routes, and HTTP methods remain available.

Redaction is key-based. Applications must not attach sensitive values under misleading keys or place resident data in exception messages. Product-specific fields still require a privacy review before being added to Sentry context.

Configuration surface

Everything the library reads from the environment or Django settings:

Name Kind Default Meaning
APP_ENV env var local Environment label in diagnostics and Sentry events; overridden by PATAPSCO_ENVIRONMENT when set
APP_RELEASE env var Release identifier in diagnostics and Sentry events; overridden by PATAPSCO_RELEASE when set
APP_LOG_FORMAT env var json json or pretty output from build_logging_config()
APP_LOG_LEVEL env var INFO Root log level from build_logging_config()
SENTRY_DSN env var Enables configure_sentry(); absent means Sentry stays off
PATAPSCO_SERVICE_NAME Django setting project name Service label in the diagnostics payload
PATAPSCO_ENVIRONMENT Django setting APP_ENV env var Overrides the diagnostics environment field via Django settings instead of the process environment (a real override_settings test seam)
PATAPSCO_RELEASE Django setting APP_RELEASE env var Overrides the diagnostics release field via Django settings instead of the process environment (a real override_settings test seam)
PATAPSCO_DIAGNOSTICS_PUBLIC Django setting False Security-relevant: flips /api/diagnostics from IsAdminUser to AllowAny. Leave False unless the deployment deliberately publishes runtime metadata

Download files

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

Source Distribution

baltimore_patapsco-0.9.7.tar.gz (319.2 kB view details)

Uploaded Source

Built Distribution

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

baltimore_patapsco-0.9.7-py3-none-any.whl (386.6 kB view details)

Uploaded Python 3

File details

Details for the file baltimore_patapsco-0.9.7.tar.gz.

File metadata

  • Download URL: baltimore_patapsco-0.9.7.tar.gz
  • Upload date:
  • Size: 319.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.11.28 {"installer":{"name":"uv","version":"0.11.28","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for baltimore_patapsco-0.9.7.tar.gz
Algorithm Hash digest
SHA256 d2f019db0be5c8a8736cd5f9c6be7536e6e2d2397fd047fe89b88ebdcf30e251
MD5 0342beb179774c10f13bc1e56922db38
BLAKE2b-256 cf9070f0345d33234f9a11541e1af2e31465f28d5498d150c2f77f1ceff40cc1

See more details on using hashes here.

File details

Details for the file baltimore_patapsco-0.9.7-py3-none-any.whl.

File metadata

  • Download URL: baltimore_patapsco-0.9.7-py3-none-any.whl
  • Upload date:
  • Size: 386.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.11.28 {"installer":{"name":"uv","version":"0.11.28","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for baltimore_patapsco-0.9.7-py3-none-any.whl
Algorithm Hash digest
SHA256 24bbb3c87329072d8ea7c40e31b9d607a72c5b23d55d92e121e5af2ede4b4af3
MD5 f7760c68d40987c640a75c4b826a20a2
BLAKE2b-256 0534aa9ae69aeb1ab66520b52610e31048ce16661b80039ca00f051453b0bb0f

See more details on using hashes here.

Release history Release notifications | RSS feed

0.12.1

2 files

0.12.0

2 files

0.11.0

2 files

0.10.2

2 files

0.10.1

2 files

0.10.0

2 files

0.9.14

2 files

0.9.13

2 files

0.9.12

2 files

0.9.11

2 files

0.9.10

2 files

0.9.9

2 files

0.9.8

2 files

This release

0.9.7 This release

2 files

0.9.6

2 files

0.9.5

2 files

0.9.4

2 files

0.9.3

2 files

0.9.2

2 files

0.9.1

2 files

0.9.0

2 files

0.8.2

2 files

0.8.1

2 files

0.8.0

2 files

0.7.2

2 files

0.7.1

2 files

0.7.0

2 files

0.6.24

2 files

0.6.23

2 files

0.6.22

2 files

0.6.21

2 files

0.6.20

2 files

0.6.19

2 files

0.6.18

2 files

0.6.17

2 files

0.6.16

2 files

0.6.15

2 files

0.6.14

2 files

0.6.13

2 files

0.6.12

2 files

0.6.11

2 files

0.6.10

2 files

0.6.9

2 files

0.6.8

2 files

0.6.7

2 files

0.6.6

2 files

0.6.5

2 files

0.6.4

2 files

0.6.3

2 files

0.6.2

2 files

0.6.1

2 files

0.6.0

2 files

0.5.5

2 files

0.5.4

2 files

0.5.3

2 files

0.5.2

2 files

0.5.1

2 files

0.5.0

2 files

0.4.8

2 files

0.4.7

2 files

0.4.6

2 files

0.4.5

2 files

0.4.4

2 files

0.4.3

2 files

0.4.2

2 files

0.4.1

2 files

0.4.0

2 files

0.3.0

2 files

0.2.0

2 files

0.1.6

2 files

0.1.5

2 files

0.1.3

2 files

0.1.2

2 files

0.1.1

2 files

0.1.0

2 files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page