Skip to main content

Swastik Codes Docs for Python

API documentation and a request collection for your Python web app, built from the OpenAPI document you already have. Install it, add one line, and you get two pages:

URL What it is
/swc/docs Full documentation: introduction, authentication, every request with its parameters, body, responses, code samples (cURL, JavaScript, Python, Go, PHP) and example responses. Search, deep links, light and dark themes.
/swc/collection Every request in a collection tree. Fill in params, auth, headers and body (form-data, x-www-form-urlencoded, raw or binary), press Send, and read the response (pretty JSON, headers, status, time, size). A code snippet panel shows the request in cURL, JavaScript, Python, Go or PHP.
/swc/openapi.json The document both pages read, with your edits applied.

Both pages have a Run in Swastik Codes button that opens the API in Swastik Codes as a collection.

  • No dependencies. Standard library only.
  • Small. The whole UI is one script and one stylesheet, about 29 KB over the wire, precompressed (brotli and gzip) and cached for a year.
  • Cheap to serve. The merged document is built once and cached until your spec or config changes. Spec responses carry an ETag, so repeat visits get 304.

FastAPI

pip install swastik-codes
from fastapi import FastAPI
from swastik_codes import mount

app = FastAPI(title="My API")

# ... your routes ...

mount(app, config="swastik-codes.json")   # /swc/docs and /swc/collection

mount() reads FastAPI's own cached app.openapi(). FastAPI's /docs and /redoc keep working. Turn them off with FastAPI(docs_url=None, redoc_url=None) if you only want these pages. To serve them at /docs instead, use mount(app, prefix="") together with docs_url=None.

Starlette works the same way. Pass spec= with your document, because Starlette has no app.openapi().

Flask

Flask has no OpenAPI generator of its own. Pass the document from the library you use (flask-smorest, apispec) or a dict:

from swastik_codes import init_flask

init_flask(app, spec=lambda: api.spec.to_dict(), config="swastik-codes.json")

Django

Use the document from drf-spectacular (or any generator). Cache it so it is built once:

# urls.py (root)
import functools
from drf_spectacular.generators import SchemaGenerator
from swastik_codes import django_urls

spec = functools.cache(lambda: SchemaGenerator().get_schema(request=None, public=True))
urlpatterns += django_urls(spec=spec, config="swastik-codes.json")

Any ASGI or WSGI app

from swastik_codes import SwastikCodesMiddleware, SwastikCodesWSGI

app = SwastikCodesMiddleware(app, spec=my_openapi_dict)        # ASGI: Litestar, Quart, ...
wsgi_app = SwastikCodesWSGI(wsgi_app, spec=my_openapi_dict)    # WSGI: Bottle, Pyramid, ...

spec is always a dict or a function that returns one. A function is called on each page load, so it should be cheap or cached. The merge is only redone when it returns a different object.

Editing the pages: swastik-codes.json

python -m swastik_codes init      # writes a starter swastik-codes.json

Every field is optional. Your OpenAPI document provides the rest. The file is re-read when it changes, so you can edit it and reload the page.

{
  "title": "Flight OTA API",
  "version": "2.0",
  "description": "Markdown introduction.\n\n## Getting started\n\n1. Get a token.\n2. Send it as a bearer token.",
  "servers": [
    { "url": "https://sandbox.example.com", "description": "Sandbox" },
    { "url": "https://api.example.com", "description": "Production" }
  ],
  "theme": { "accent": "#0d9488", "mode": "system" },
  "tags": { "Search": { "name": "Flight search", "description": "Find flights." } },
  "groups": [
    { "name": "Start here", "tags": ["Authentication"] },
    { "name": "Flights", "tags": ["Search", "Bookings"] }
  ],
  "operations": {
    "GET /v2/bookings/{booking_id}": { "summary": "Read a held booking", "description": "Markdown." },
    "deleteCache": { "hidden": true }
  },
  "hide": ["/internal/*", "DELETE /admin/*"],
  "pages": [{ "title": "Errors", "body": "Markdown, tables included." }],
  "links": [{ "label": "Support", "url": "https://example.com/support" }],
  "languages": ["curl", "javascript", "python", "go", "php"]
}
Field Effect
title, version, description Replace info.*. The description is Markdown.
servers Base URLs readers pick from (the first is the default). Readers can also enter their own.
theme Accent colour, and the default theme (system, light or dark).
tags Display name and description per tag (each tag is a folder).
groups Sections that hold tags, in order.
operations Per request, keyed by "METHOD /path" or operationId: summary, description, tags, deprecated, hidden.
hide Paths to leave out. * matches anything. Prefix with a method to hide only that method.
pages Extra Markdown pages under Introduction.
links Links on the introduction.
languages Code sample languages and their order.

The Swastik Codes logo, the "Built with Swastik Codes" credit and the Run in Swastik Codes button are part of the pages. They have no setting. Keys such as logo or hideRunButton are ignored with a warning.

Notes

  • Sending requests. The collection page sends requests from the browser. Requests to the same server always work. Requests to another server need that server to allow CORS for your docs origin, as for any page that calls an API from the browser.
  • Credentials. Tokens you enter are kept in the tab's session storage. They are never sent anywhere except with your requests.
  • Security headers. The pages are sent with a strict Content-Security-Policy: no inline scripts, and scripts and styles from this server only. Pass csp=False to turn it off.
  • Run in Swastik Codes opens https://swastik.codes/app?import=<your openapi.json>. For an API on localhost it offers the file to download instead, because a website can't reach your computer.

Licence

Proprietary, free to use. See LICENSE.md. © Shwastik Tech Solutions Pvt Ltd.

Metadata

Release files for swastik-codes 0.2.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for swastik-codes 0.2.0
File Size Uploaded Provenance Actions
swastik_codes-0.2.0.tar.gz 113.8 kB Without provenance Details for swastik_codes-0.2.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for swastik-codes 0.2.0
File Interpreter ABI Platform Actions
swastik_codes-0.2.0-py3-none-any.whl Python 3 none any Details for swastik_codes-0.2.0-py3-none-any.whl

Total release size: 227.1 kB

Release files / swastik_codes-0.2.0.tar.gz

Download URL swastik_codes-0.2.0.tar.gz
Size 113.8 kB
Tags Source
SHA-256 checksum
How to use checksums
8adc0e2e59c2c556a3cf09ca5a2959c40f9f45a6bf33567e6b49be80bb595bf8
BLAKE2b-256 checksum
How to use checksums
18e2c47d67fcb0f71a6b9b11f8d895b7fa87f587603b15ca9a5d30e5a4933b25
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.12.17 {"installer":{"name":"uv","version":"0.12.17","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"25.04","id":"plucky","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

Release files / swastik_codes-0.2.0-py3-none-any.whl

Download URL swastik_codes-0.2.0-py3-none-any.whl
Size 113.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
71f58f0991efad77afeb08ca1a5b148fa0603aaf47a4405d998d6f4533324913
BLAKE2b-256 checksum
How to use checksums
c966e30da4268c8ebfdf81017478755bd1ba619083c572878f49417ac1a7bc5f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.12.17 {"installer":{"name":"uv","version":"0.12.17","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"25.04","id":"plucky","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

Security for swastik-codes 0.2.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.2.0 This release

2 release files No provenance

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