schemawatch-api 0.1.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (37) hide show
  1. schemawatch_api-0.1.0/.gitignore +62 -0
  2. schemawatch_api-0.1.0/LICENSE +21 -0
  3. schemawatch_api-0.1.0/PKG-INFO +39 -0
  4. schemawatch_api-0.1.0/README.md +6 -0
  5. schemawatch_api-0.1.0/alembic/env.py +73 -0
  6. schemawatch_api-0.1.0/alembic/script.py.mako +26 -0
  7. schemawatch_api-0.1.0/alembic/versions/0001_initial_schema.py +99 -0
  8. schemawatch_api-0.1.0/alembic.ini +38 -0
  9. schemawatch_api-0.1.0/pyproject.toml +51 -0
  10. schemawatch_api-0.1.0/schemawatch_api/__init__.py +3 -0
  11. schemawatch_api-0.1.0/schemawatch_api/__main__.py +45 -0
  12. schemawatch_api-0.1.0/schemawatch_api/app.py +445 -0
  13. schemawatch_api-0.1.0/schemawatch_api/config.py +101 -0
  14. schemawatch_api-0.1.0/schemawatch_api/database.py +30 -0
  15. schemawatch_api-0.1.0/schemawatch_api/models.py +112 -0
  16. schemawatch_api-0.1.0/schemawatch_api/py.typed +1 -0
  17. schemawatch_api-0.1.0/schemawatch_api/schemas.py +149 -0
  18. schemawatch_api-0.1.0/schemawatch_api/scripts/export_openapi.py +34 -0
  19. schemawatch_api-0.1.0/schemawatch_api/scripts/seed_demo.py +256 -0
  20. schemawatch_api-0.1.0/schemawatch_api/service.py +523 -0
  21. schemawatch_api-0.1.0/schemawatch_api/sse.py +67 -0
  22. schemawatch_api-0.1.0/schemawatch_api/store.py +177 -0
  23. schemawatch_api-0.1.0/scripts/__init__.py +1 -0
  24. schemawatch_api-0.1.0/scripts/export_openapi.py +42 -0
  25. schemawatch_api-0.1.0/scripts/seed_demo.py +283 -0
  26. schemawatch_api-0.1.0/tests/conftest.py +48 -0
  27. schemawatch_api-0.1.0/tests/test_auth.py +123 -0
  28. schemawatch_api-0.1.0/tests/test_cli_startup.py +158 -0
  29. schemawatch_api-0.1.0/tests/test_endpoints.py +126 -0
  30. schemawatch_api-0.1.0/tests/test_events.py +123 -0
  31. schemawatch_api-0.1.0/tests/test_frontend_mount.py +64 -0
  32. schemawatch_api-0.1.0/tests/test_ingest_and_accept_flow.py +118 -0
  33. schemawatch_api-0.1.0/tests/test_privacy_scan.py +82 -0
  34. schemawatch_api-0.1.0/tests/test_restart_persistence.py +100 -0
  35. schemawatch_api-0.1.0/tests/test_scripts.py +126 -0
  36. schemawatch_api-0.1.0/tests/test_sse_stream.py +106 -0
  37. schemawatch_api-0.1.0/tests/test_stats_config.py +66 -0
@@ -0,0 +1,62 @@
1
+ # Python
2
+ __pycache__/
3
+ *.py[cod]
4
+ *$py.class
5
+ *.so
6
+ .Python
7
+ build/
8
+ develop-eggs/
9
+ dist/
10
+ downloads/
11
+ eggs/
12
+ .eggs/
13
+ /lib/
14
+ /lib64/
15
+ parts/
16
+ sdist/
17
+ var/
18
+ wheels/
19
+ share/python-wheels/
20
+ *.egg-info/
21
+ .installed.cfg
22
+ *.egg
23
+
24
+ # Virtual environments
25
+ .venv/
26
+ venv/
27
+ ENV/
28
+ env/
29
+
30
+ # Testing & Coverage
31
+ .coverage
32
+ .coverage.*
33
+ coverage/
34
+ htmlcov/
35
+ .pytest_cache/
36
+ .hypothesis/
37
+
38
+ # Type checking & Linters
39
+ .mypy_cache/
40
+ .ruff_cache/
41
+
42
+ # Environment & Secrets
43
+ .env*
44
+ !.env.example
45
+
46
+ # Databases & Runtime state
47
+ *.db
48
+ *.sqlite
49
+ *.sqlite3
50
+
51
+ # Frontend & Dependencies
52
+ node_modules/
53
+ dist/
54
+
55
+ # OS / IDE
56
+ .DS_Store
57
+ Thumbs.db
58
+ *.swp
59
+ *.swo
60
+ .vscode/
61
+ .idea/
62
+
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 schemawatch contributors
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,39 @@
1
+ Metadata-Version: 2.5
2
+ Name: schemawatch-api
3
+ Version: 0.1.0
4
+ Summary: FastAPI server and API for schemawatch
5
+ Project-URL: Homepage, https://github.com/Mohd-obaidullah/schemawatch
6
+ Project-URL: Source, https://github.com/Mohd-obaidullah/schemawatch
7
+ Project-URL: Issues, https://github.com/Mohd-obaidullah/schemawatch/issues
8
+ Project-URL: Changelog, https://github.com/Mohd-obaidullah/schemawatch/blob/main/CHANGELOG.md
9
+ Author: Mohd Obaidullah
10
+ License-Expression: MIT
11
+ License-File: LICENSE
12
+ Keywords: api,contract-testing,drift,fastapi,monitoring,schema
13
+ Classifier: Development Status :: 4 - Beta
14
+ Classifier: Intended Audience :: Developers
15
+ Classifier: License :: OSI Approved :: MIT License
16
+ Classifier: Programming Language :: Python :: 3
17
+ Classifier: Programming Language :: Python :: 3.10
18
+ Classifier: Programming Language :: Python :: 3.11
19
+ Classifier: Programming Language :: Python :: 3.12
20
+ Classifier: Programming Language :: Python :: 3.13
21
+ Classifier: Topic :: Software Development :: Testing
22
+ Classifier: Typing :: Typed
23
+ Requires-Python: >=3.10
24
+ Requires-Dist: alembic>=1.13.0
25
+ Requires-Dist: fastapi>=0.111.0
26
+ Requires-Dist: psycopg[binary]>=3.1.0
27
+ Requires-Dist: pydantic-settings>=2.3.0
28
+ Requires-Dist: pydantic>=2.7.0
29
+ Requires-Dist: schemawatch-core>=0.1.0
30
+ Requires-Dist: sqlalchemy>=2.0.30
31
+ Requires-Dist: uvicorn>=0.30.0
32
+ Description-Content-Type: text/markdown
33
+
34
+ # apps/api
35
+
36
+ FastAPI server and CLI for schemawatch.
37
+ Serves `apps/web/dist` in production.
38
+
39
+ *Planned for Milestone M3 and M5.*
@@ -0,0 +1,6 @@
1
+ # apps/api
2
+
3
+ FastAPI server and CLI for schemawatch.
4
+ Serves `apps/web/dist` in production.
5
+
6
+ *Planned for Milestone M3 and M5.*
@@ -0,0 +1,73 @@
1
+ from __future__ import annotations
2
+
3
+ import os
4
+ from logging.config import fileConfig
5
+
6
+ from alembic import context
7
+ from schemawatch_api.config import Settings
8
+ from schemawatch_api.models import Base
9
+ from sqlalchemy import engine_from_config, pool
10
+
11
+ # this is the Alembic Config object, which provides
12
+ # access to the values within the .ini file in use.
13
+ config = context.config
14
+
15
+ # Interpret the config file for Python logging.
16
+ if config.config_file_name is not None:
17
+ fileConfig(config.config_file_name)
18
+
19
+ # Model metadata for autogenerate support
20
+ target_metadata = Base.metadata
21
+
22
+
23
+ def get_url() -> str:
24
+ # Allow override from environment or default from schemawatch settings
25
+ env_url = os.environ.get("SCHEMAWATCH_DATABASE_URL")
26
+ if env_url:
27
+ return env_url
28
+ try:
29
+ settings = Settings(dev_mode=True)
30
+ return settings.database_url
31
+ except Exception:
32
+ return "sqlite:///./schemawatch.db"
33
+
34
+
35
+ def run_migrations_offline() -> None:
36
+ """Run migrations in 'offline' mode."""
37
+ url = get_url()
38
+ context.configure(
39
+ url=url,
40
+ target_metadata=target_metadata,
41
+ literal_binds=True,
42
+ dialect_opts={"paramstyle": "named"},
43
+ )
44
+
45
+ with context.begin_transaction():
46
+ context.run_migrations()
47
+
48
+
49
+ def run_migrations_online() -> None:
50
+ """Run migrations in 'online' mode."""
51
+ configuration = config.get_section(config.config_ini_section, {})
52
+ configuration["sqlalchemy.url"] = get_url()
53
+
54
+ connectable = engine_from_config(
55
+ configuration,
56
+ prefix="sqlalchemy.",
57
+ poolclass=pool.NullPool,
58
+ )
59
+
60
+ with connectable.connect() as connection:
61
+ context.configure(
62
+ connection=connection,
63
+ target_metadata=target_metadata,
64
+ )
65
+
66
+ with context.begin_transaction():
67
+ context.run_migrations()
68
+
69
+
70
+ if context.is_offline_mode():
71
+ run_migrations_offline()
72
+ else:
73
+ run_migrations_online()
@@ -0,0 +1,26 @@
1
+ """${message}
2
+
3
+ Revision ID: ${up_revision}
4
+ Revises: ${down_revision | comma,n}
5
+ Create Date: ${create_date}
6
+
7
+ """
8
+ from typing import Sequence, Union
9
+
10
+ from alembic import op
11
+ import sqlalchemy as sa
12
+ ${imports if imports else ""}
13
+
14
+ # revision identifiers, used by Alembic.
15
+ revision: str = ${repr(up_revision)}
16
+ down_revision: Union[str, None] = ${repr(down_revision)}
17
+ branch_labels: Union[str, Sequence[str], None] = ${repr(branch_labels)}
18
+ depends_on: Union[str, Sequence[str], None] = ${repr(depends_on)}
19
+
20
+
21
+ def upgrade() -> None:
22
+ ${upgrades if upgrades else "pass"}
23
+
24
+
25
+ def downgrade() -> None:
26
+ ${downgrades if downgrades else "pass"}
@@ -0,0 +1,99 @@
1
+ """initial schema
2
+
3
+ Revision ID: 0001_initial
4
+ Revises:
5
+ Create Date: 2026-10-17 00:00:00.000000
6
+
7
+ """
8
+
9
+ from collections.abc import Sequence
10
+
11
+ import sqlalchemy as sa
12
+ from alembic import op
13
+
14
+ # revision identifiers, used by Alembic.
15
+ revision: str = "0001_initial"
16
+ down_revision: str | None = None
17
+ branch_labels: str | Sequence[str] | None = None
18
+ depends_on: str | Sequence[str] | None = None
19
+
20
+
21
+ def upgrade() -> None:
22
+ # 1. endpoints
23
+ op.create_table(
24
+ "endpoints",
25
+ sa.Column("id", sa.Integer(), autoincrement=True, nullable=False),
26
+ sa.Column("vendor", sa.String(length=255), nullable=False),
27
+ sa.Column("endpoint", sa.String(length=1024), nullable=False),
28
+ sa.Column("sample_count", sa.Integer(), nullable=False, server_default="0"),
29
+ sa.Column("current_baseline_version", sa.Integer(), nullable=True),
30
+ sa.Column("created_at", sa.DateTime(), nullable=False),
31
+ sa.Column("updated_at", sa.DateTime(), nullable=False),
32
+ sa.PrimaryKeyConstraint("id"),
33
+ sa.UniqueConstraint("vendor", "endpoint", name="uq_endpoints_vendor_endpoint"),
34
+ )
35
+ op.create_index("ix_endpoints_vendor", "endpoints", ["vendor"])
36
+ op.create_index("ix_endpoints_endpoint", "endpoints", ["endpoint"])
37
+
38
+ # 2. baselines
39
+ op.create_table(
40
+ "baselines",
41
+ sa.Column("id", sa.Integer(), autoincrement=True, nullable=False),
42
+ sa.Column("endpoint_id", sa.Integer(), nullable=False),
43
+ sa.Column("version", sa.Integer(), nullable=False),
44
+ sa.Column("schema_json", sa.Text(), nullable=False),
45
+ sa.Column("created_at", sa.DateTime(), nullable=False),
46
+ sa.ForeignKeyConstraint(["endpoint_id"], ["endpoints.id"], ondelete="CASCADE"),
47
+ sa.PrimaryKeyConstraint("id"),
48
+ sa.UniqueConstraint("endpoint_id", "version", name="uq_baselines_endpoint_version"),
49
+ )
50
+ op.create_index("ix_baselines_endpoint_id", "baselines", ["endpoint_id"])
51
+
52
+ # 3. drift_events
53
+ op.create_table(
54
+ "drift_events",
55
+ sa.Column("id", sa.Integer(), autoincrement=True, nullable=False),
56
+ sa.Column("endpoint_id", sa.Integer(), nullable=False),
57
+ sa.Column("vendor", sa.String(length=255), nullable=False),
58
+ sa.Column("endpoint", sa.String(length=1024), nullable=False),
59
+ sa.Column("field_path", sa.String(length=1024), nullable=False),
60
+ sa.Column("kind", sa.String(length=64), nullable=False),
61
+ sa.Column("severity", sa.String(length=32), nullable=False),
62
+ sa.Column("was_value", sa.String(length=255), nullable=True),
63
+ sa.Column("now_value", sa.String(length=255), nullable=True),
64
+ sa.Column("detail", sa.Text(), nullable=True),
65
+ sa.Column("observed_schema_json", sa.Text(), nullable=True),
66
+ sa.Column("acknowledged", sa.Boolean(), nullable=False, server_default=sa.false()),
67
+ sa.Column("acknowledged_at", sa.DateTime(), nullable=True),
68
+ sa.Column("detected_at", sa.DateTime(), nullable=False),
69
+ sa.ForeignKeyConstraint(["endpoint_id"], ["endpoints.id"], ondelete="CASCADE"),
70
+ sa.PrimaryKeyConstraint("id"),
71
+ )
72
+ op.create_index("ix_drift_events_endpoint_id", "drift_events", ["endpoint_id"])
73
+ op.create_index("ix_drift_events_vendor", "drift_events", ["vendor"])
74
+ op.create_index("ix_drift_events_endpoint", "drift_events", ["endpoint"])
75
+ op.create_index("ix_drift_events_kind", "drift_events", ["kind"])
76
+ op.create_index("ix_drift_events_severity", "drift_events", ["severity"])
77
+ op.create_index("ix_drift_events_acknowledged", "drift_events", ["acknowledged"])
78
+ op.create_index("ix_drift_events_detected_at", "drift_events", ["detected_at"])
79
+
80
+ # 4. alert_deliveries
81
+ op.create_table(
82
+ "alert_deliveries",
83
+ sa.Column("id", sa.Integer(), autoincrement=True, nullable=False),
84
+ sa.Column("drift_event_id", sa.Integer(), nullable=False),
85
+ sa.Column("channel", sa.String(length=64), nullable=False),
86
+ sa.Column("status", sa.String(length=32), nullable=False),
87
+ sa.Column("delivered_at", sa.DateTime(), nullable=False),
88
+ sa.Column("error_message", sa.Text(), nullable=True),
89
+ sa.ForeignKeyConstraint(["drift_event_id"], ["drift_events.id"], ondelete="CASCADE"),
90
+ sa.PrimaryKeyConstraint("id"),
91
+ )
92
+ op.create_index("ix_alert_deliveries_drift_event_id", "alert_deliveries", ["drift_event_id"])
93
+
94
+
95
+ def downgrade() -> None:
96
+ op.drop_table("alert_deliveries")
97
+ op.drop_table("drift_events")
98
+ op.drop_table("baselines")
99
+ op.drop_table("endpoints")
@@ -0,0 +1,38 @@
1
+ [alembic]
2
+ script_location = %(here)s/alembic
3
+ prepend_sys_path = %(here)s
4
+ version_path_separator = os
5
+
6
+ [loggers]
7
+ keys = root,sqlalchemy,alembic
8
+
9
+ [handlers]
10
+ keys = console
11
+
12
+ [formatters]
13
+ keys = generic
14
+
15
+ [logger_root]
16
+ level = WARN
17
+ handlers = console
18
+ qualname =
19
+
20
+ [logger_sqlalchemy]
21
+ level = WARN
22
+ handlers =
23
+ qualname = sqlalchemy.engine
24
+
25
+ [logger_alembic]
26
+ level = INFO
27
+ handlers =
28
+ qualname = alembic
29
+
30
+ [handler_console]
31
+ class = StreamHandler
32
+ args = (sys.stderr,)
33
+ level = NOTSET
34
+ formatter = generic
35
+
36
+ [formatter_generic]
37
+ format = %(levelname)-5.5s [%(name)s] %(message)s
38
+ datefmt = %H:%M:%S
@@ -0,0 +1,51 @@
1
+ [build-system]
2
+ requires = ["hatchling"]
3
+ build-backend = "hatchling.build"
4
+
5
+ [project]
6
+ name = "schemawatch-api"
7
+ version = "0.1.0"
8
+ description = "FastAPI server and API for schemawatch"
9
+ readme = "README.md"
10
+ requires-python = ">=3.10"
11
+ license = "MIT"
12
+ license-files = ["LICENSE"]
13
+ authors = [{ name = "Mohd Obaidullah" }]
14
+ keywords = ["api", "schema", "drift", "fastapi", "monitoring", "contract-testing"]
15
+ classifiers = [
16
+ "Development Status :: 4 - Beta",
17
+ "Intended Audience :: Developers",
18
+ "License :: OSI Approved :: MIT License",
19
+ "Programming Language :: Python :: 3",
20
+ "Programming Language :: Python :: 3.10",
21
+ "Programming Language :: Python :: 3.11",
22
+ "Programming Language :: Python :: 3.12",
23
+ "Programming Language :: Python :: 3.13",
24
+ "Topic :: Software Development :: Testing",
25
+ "Typing :: Typed",
26
+ ]
27
+ dependencies = [
28
+ "schemawatch-core>=0.1.0",
29
+ "fastapi>=0.111.0",
30
+ "uvicorn>=0.30.0",
31
+ "pydantic>=2.7.0",
32
+ "pydantic-settings>=2.3.0",
33
+ "sqlalchemy>=2.0.30",
34
+ "alembic>=1.13.0",
35
+ "psycopg[binary]>=3.1.0",
36
+ ]
37
+
38
+ [project.urls]
39
+ Homepage = "https://github.com/Mohd-obaidullah/schemawatch"
40
+ Source = "https://github.com/Mohd-obaidullah/schemawatch"
41
+ Issues = "https://github.com/Mohd-obaidullah/schemawatch/issues"
42
+ Changelog = "https://github.com/Mohd-obaidullah/schemawatch/blob/main/CHANGELOG.md"
43
+
44
+ [project.scripts]
45
+ schemawatch-api = "schemawatch_api.__main__:main"
46
+
47
+ [tool.hatch.build.targets.wheel]
48
+ packages = ["schemawatch_api"]
49
+
50
+ [tool.uv.sources]
51
+ schemawatch-core = { workspace = true }
@@ -0,0 +1,3 @@
1
+ from __future__ import annotations
2
+
3
+ __version__ = "0.1.0"
@@ -0,0 +1,45 @@
1
+ from __future__ import annotations
2
+
3
+ import argparse
4
+ import logging
5
+ import os
6
+ import sys
7
+
8
+ import uvicorn
9
+
10
+ from schemawatch_api.config import Settings
11
+
12
+
13
+ def main() -> None:
14
+ """Entry point for schemawatch-api CLI / python -m schemawatch_api."""
15
+ parser = argparse.ArgumentParser(description="Run schemawatch API server")
16
+ parser.add_argument("--host", default="127.0.0.1", help="Bind socket host")
17
+ parser.add_argument("--port", type=int, default=8000, help="Bind socket port")
18
+ parser.add_argument("--dev", action="store_true", help="Run with dev mode and reload")
19
+ args = parser.parse_args()
20
+
21
+ if args.dev:
22
+ os.environ["SCHEMAWATCH_DEV_MODE"] = "true"
23
+
24
+ try:
25
+ settings = Settings()
26
+ settings.validate_token_requirement()
27
+ except ValueError as exc:
28
+ print(f"ERROR: {exc}", file=sys.stderr)
29
+ sys.exit(1)
30
+
31
+ logging.basicConfig(level=logging.INFO)
32
+ logger = logging.getLogger("schemawatch.api")
33
+ logger.info("Starting schemawatch API bound to %s:%d", args.host, args.port)
34
+
35
+ uvicorn.run(
36
+ "schemawatch_api.app:create_app",
37
+ factory=True,
38
+ host=args.host,
39
+ port=args.port,
40
+ reload=args.dev,
41
+ )
42
+
43
+
44
+ if __name__ == "__main__":
45
+ main()