Skip to main content

Simple web admin interface to manage .json file

Project description

Json-admin

Библиотека с реализацией простого интерфейса для управления .json-файлом с настройками приложения.

Быстрый старт

from litestar import Litestar
from pydantic import BaseModel, Field

from jsonadmin import Admin, HtmlPage, JsonPage


class AppSettings(BaseModel):
    """Настройки приложения."""

    debug: bool = Field(default=False, description="Включает debug-режим")
    retries: int = Field(default=3, ge=0, description="Количество повторных попыток")


class FeatureFlags(BaseModel):
    """Настройки feature flags."""

    use_cache: bool = Field(default=True, description="Включает кеширование")
    beta_mode: bool = Field(default=False, description="Включает beta-режим")


app = Litestar(route_handlers=[])
admin = Admin(
    app=app,
    passwd="super-strong-password",
    title="My App Admin",
    index="index.html",
    login="login.html",
    pages=[
        HtmlPage(
            slug="info",
            title="Информация",
            icon="fa-solid fa-circle-info",
            content="""
            <h2>Welcome</h2>
            <p>This page is read-only and renders embedded HTML block.</p>
            """,
        ),
        JsonPage(
            slug="settings",
            title="Настройки",
            file_path="data/app_settings.json",
            model=AppSettings,
            icon="fa-solid fa-gear",
        ),
        JsonPage(
            slug="features",
            title="Флаги",
            file_path="data/feature_flags.json",
            model=FeatureFlags,
            icon="fa-solid fa-flag",
        ),
    ],
    base_url="/",
)

После запуска:

  • GET / покажет форму входа по паролю.
  • после входа доступны вкладки-страницы с JSON-редактором.
  • HtmlPage — read-only вкладка с HTML-блоком. content может быть:
    • встроенной строкой HTML,
    • путём к .html файлу,
    • Callable[[], str].
  • кнопка Сохранить валидирует данные через обязательную Pydantic-модель и сохраняет JSON в файл.
  • можно переопределить интерфейс через Jinja-шаблоны в jsonadmin/html/ (по умолчанию) или через templates_dir=....
  • для вкладок можно передать icon с классом Font Awesome, например fa-solid fa-gear.

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

json_admin-0.1.0.tar.gz (10.1 kB view details)

Uploaded Source

Built Distribution

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

json_admin-0.1.0-py3-none-any.whl (11.5 kB view details)

Uploaded Python 3

File details

Details for the file json_admin-0.1.0.tar.gz.

File metadata

  • Download URL: json_admin-0.1.0.tar.gz
  • Upload date:
  • Size: 10.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for json_admin-0.1.0.tar.gz
Algorithm Hash digest
SHA256 93e00a0d3d8dab3f94fa51845ce58472eea92cdd4d5c85848689b0598ed22079
MD5 eb1b7777fc036f667e50c3b9dab977bf
BLAKE2b-256 873c382348458f605c9fbe5d0dda3fc5f56646e0ebab6dc356e51d4b832c8149

See more details on using hashes here.

Provenance

The following attestation bundles were made for json_admin-0.1.0.tar.gz:

Publisher: pypi.yml on LoveBloodAndDiamonds/json-admin

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file json_admin-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: json_admin-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 11.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for json_admin-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 95674db9bd71fb0e864f45c30dd89e965243d6042793c1142db6538810dec3de
MD5 3de3ef14bf37f79d8cfe74333674d1fc
BLAKE2b-256 68dc36a7c7680c3c1ed3d12d42e5d16d9ddd45999c5905012875a092f42286a0

See more details on using hashes here.

Provenance

The following attestation bundles were made for json_admin-0.1.0-py3-none-any.whl:

Publisher: pypi.yml on LoveBloodAndDiamonds/json-admin

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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