pywebguard 0.0.0__py3-none-any.whl

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 (43) hide show
  1. pywebguard/__init__.py +87 -0
  2. pywebguard/cli.py +1022 -0
  3. pywebguard/core/__init__.py +0 -0
  4. pywebguard/core/base.py +792 -0
  5. pywebguard/core/config.py +455 -0
  6. pywebguard/filters/__init__.py +0 -0
  7. pywebguard/filters/base.py +44 -0
  8. pywebguard/filters/ip_filter.py +233 -0
  9. pywebguard/filters/user_agent.py +102 -0
  10. pywebguard/frameworks/__init__.py +0 -0
  11. pywebguard/frameworks/_fastapi.py +191 -0
  12. pywebguard/frameworks/_flask.py +182 -0
  13. pywebguard/limiters/__init__.py +0 -0
  14. pywebguard/limiters/base.py +46 -0
  15. pywebguard/limiters/rate_limit.py +415 -0
  16. pywebguard/logging/__init__.py +0 -0
  17. pywebguard/logging/backends/__init__.py +17 -0
  18. pywebguard/logging/backends/_elasticsearch.py +307 -0
  19. pywebguard/logging/backends/_meilisearch.py +310 -0
  20. pywebguard/logging/backends/_mongodb.py +303 -0
  21. pywebguard/logging/base.py +117 -0
  22. pywebguard/logging/logger.py +408 -0
  23. pywebguard/security/__init__.py +0 -0
  24. pywebguard/security/base.py +44 -0
  25. pywebguard/security/cors.py +204 -0
  26. pywebguard/security/penetration.py +265 -0
  27. pywebguard/storage/__init__.py +0 -0
  28. pywebguard/storage/_mongodb.py +396 -0
  29. pywebguard/storage/_postgresql.py +539 -0
  30. pywebguard/storage/_redis.py +314 -0
  31. pywebguard/storage/_sqlite.py +374 -0
  32. pywebguard/storage/_tinydb.py +271 -0
  33. pywebguard/storage/base.py +327 -0
  34. pywebguard/storage/memory.py +245 -0
  35. pywebguard/utils/__init__.py +0 -0
  36. pywebguard/utils/ip.py +84 -0
  37. pywebguard/utils/request.py +65 -0
  38. pywebguard-0.0.0.dist-info/LICENSE +21 -0
  39. pywebguard-0.0.0.dist-info/METADATA +368 -0
  40. pywebguard-0.0.0.dist-info/RECORD +43 -0
  41. pywebguard-0.0.0.dist-info/WHEEL +5 -0
  42. pywebguard-0.0.0.dist-info/entry_points.txt +2 -0
  43. pywebguard-0.0.0.dist-info/top_level.txt +1 -0
pywebguard/__init__.py ADDED
@@ -0,0 +1,87 @@
1
+ """
2
+ PyWebGuard - A comprehensive security library for Python web applications.
3
+
4
+ This package provides middleware and utilities for IP filtering, rate limiting,
5
+ and other security features for FastAPI and Flask with both sync and async support.
6
+
7
+ Features:
8
+ - IP filtering: Block or allow requests based on IP addresses
9
+ - Rate limiting: Limit request rates to prevent abuse
10
+ - User agent filtering: Block requests from specific user agents
11
+ - Penetration detection: Detect and block potential penetration attempts
12
+ - CORS handling: Configure Cross-Origin Resource Sharing
13
+ - Framework integration: Ready-to-use middleware for FastAPI and Flask
14
+ - Storage options: Multiple storage backends (Memory, Redis, SQLite, TinyDB)
15
+ - Async support: Full support for asynchronous web frameworks
16
+ """
17
+
18
+ __version__ = "0.1.0"
19
+
20
+ # Core components (always available)
21
+ from pywebguard.core.base import Guard, AsyncGuard
22
+ from pywebguard.core.config import GuardConfig, RateLimitConfig
23
+ from pywebguard.storage.memory import MemoryStorage, AsyncMemoryStorage
24
+
25
+ # Optional storage backends - imported conditionally to avoid import errors
26
+ # if the required dependencies are not installed
27
+ try:
28
+ from pywebguard.storage._redis import RedisStorage, AsyncRedisStorage
29
+ except ImportError:
30
+ pass
31
+
32
+ try:
33
+ from pywebguard.storage._sqlite import SQLiteStorage, AsyncSQLiteStorage
34
+ except ImportError:
35
+ pass
36
+
37
+ try:
38
+ from pywebguard.storage._tinydb import TinyDBStorage, AsyncTinyDBStorage
39
+ except ImportError:
40
+ pass
41
+
42
+ # Framework-specific imports - imported conditionally to avoid import errors
43
+ # if the framework is not installed
44
+ try:
45
+ import fastapi
46
+ from pywebguard.frameworks._fastapi import FastAPIGuard
47
+ except ImportError:
48
+ pass
49
+
50
+ try:
51
+ import flask
52
+ from pywebguard.frameworks._flask import FlaskGuard
53
+ except ImportError:
54
+ pass
55
+
56
+ # Define what's available in the namespace
57
+ __all__ = [
58
+ # Core components
59
+ "Guard",
60
+ "AsyncGuard",
61
+ "GuardConfig",
62
+ "RateLimitConfig",
63
+ "MemoryStorage",
64
+ "AsyncMemoryStorage",
65
+ ]
66
+
67
+ # Dynamically add optional components to __all__ if they're available
68
+ import sys
69
+
70
+ current_module = sys.modules[__name__]
71
+
72
+ # Optional storage backends
73
+ for storage_class in [
74
+ "RedisStorage",
75
+ "AsyncRedisStorage",
76
+ "SQLiteStorage",
77
+ "AsyncSQLiteStorage",
78
+ "TinyDBStorage",
79
+ "AsyncTinyDBStorage",
80
+ ]:
81
+ if hasattr(current_module, storage_class):
82
+ __all__.append(storage_class)
83
+
84
+ # Framework integrations
85
+ for framework_class in ["FastAPIGuard", "FlaskGuard"]:
86
+ if hasattr(current_module, framework_class):
87
+ __all__.append(framework_class)