Coverage for astrocyte/ingest/__init__.py: 39%

31 statements  

« prev     ^ index     » next       coverage.py v7.15.0, created at 2026-07-04 05:24 +0000

1"""M4 — external data ingest (webhooks; Redis / Kafka streams; GitHub poll). 

2 

3Use :func:`astrocyte.ingest.webhook.handle_webhook_ingest` from an HTTP layer with the raw 

4request body (needed for HMAC). Optional ASGI helper: ``astrocyte.ingest.fastapi_app.create_ingest_webhook_app`` (install ``astrocyte[gateway]``; Starlette app, uvicorn-compatible). 

5Stream sources (``type: stream``, ``driver: kafka`` / ``redis``) need ``astrocyte[stream]`` (``astrocyte-ingestion-kafka``, ``astrocyte-ingestion-redis``) and ``retain=`` when building :class:`SourceRegistry`. 

6Poll sources (``type: poll``, ``driver: github``) need ``astrocyte[poll]`` (``astrocyte-ingestion-github``) and ``retain=``. 

7See ``docs/_design/product-roadmap.md`` (M4). 

8""" 

9 

10from __future__ import annotations 

11 

12from typing import Any 

13 

14from astrocyte.ingest.bank_resolve import resolve_ingest_bank_id 

15from astrocyte.ingest.hmac_auth import compute_hmac_sha256_hex, verify_hmac_sha256 

16from astrocyte.ingest.payload import parse_ingest_kafka_value, parse_ingest_stream_fields 

17from astrocyte.ingest.registry import SourceRegistry 

18from astrocyte.ingest.runtime import retain_callable_for_astrocyte 

19from astrocyte.ingest.source import IngestSource, WebhookIngestSource 

20from astrocyte.ingest.supervisor import IngestSupervisor, install_shutdown_signals, merge_source_health 

21from astrocyte.ingest.webhook import WebhookIngestResult, handle_webhook_ingest 

22 

23 

24def __getattr__(name: str) -> Any: 

25 if name == "RedisStreamIngestSource": 

26 try: 

27 from astrocyte_ingestion_redis import RedisStreamIngestSource as _RedisStreamIngestSource 

28 except ImportError as e: 

29 raise AttributeError( 

30 "RedisStreamIngestSource requires astrocyte-ingestion-redis. " 

31 "Install: pip install astrocyte-ingestion-redis or pip install 'astrocyte[stream]'." 

32 ) from e 

33 return _RedisStreamIngestSource 

34 if name == "KafkaStreamIngestSource": 

35 try: 

36 from astrocyte_ingestion_kafka import KafkaStreamIngestSource as _KafkaStreamIngestSource 

37 except ImportError as e: 

38 raise AttributeError( 

39 "KafkaStreamIngestSource requires astrocyte-ingestion-kafka. " 

40 "Install: pip install astrocyte-ingestion-kafka or pip install 'astrocyte[stream]'." 

41 ) from e 

42 return _KafkaStreamIngestSource 

43 if name == "GithubPollIngestSource": 

44 try: 

45 from astrocyte_ingestion_github import GithubPollIngestSource as _GithubPollIngestSource 

46 except ImportError as e: 

47 raise AttributeError( 

48 "GithubPollIngestSource requires astrocyte-ingestion-github. " 

49 "Install: pip install astrocyte-ingestion-github or pip install 'astrocyte[poll]'." 

50 ) from e 

51 return _GithubPollIngestSource 

52 raise AttributeError(f"module {__name__!r} has no attribute {name!r}") 

53 

54 

55# RedisStreamIngestSource / KafkaStreamIngestSource are lazy via __getattr__ (optional extras); 

56# omitting them from __all__ avoids static export checks; use `import RedisStreamIngestSource` etc. 

57__all__ = [ 

58 "IngestSource", 

59 "WebhookIngestSource", 

60 "SourceRegistry", 

61 "handle_webhook_ingest", 

62 "WebhookIngestResult", 

63 "retain_callable_for_astrocyte", 

64 "IngestSupervisor", 

65 "merge_source_health", 

66 "install_shutdown_signals", 

67 "parse_ingest_stream_fields", 

68 "parse_ingest_kafka_value", 

69 "resolve_ingest_bank_id", 

70 "compute_hmac_sha256_hex", 

71 "verify_hmac_sha256", 

72]