pywebguard 0.0.1__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.
- pywebguard/__init__.py +87 -0
- pywebguard/cli.py +1022 -0
- pywebguard/core/__init__.py +0 -0
- pywebguard/core/base.py +792 -0
- pywebguard/core/config.py +455 -0
- pywebguard/filters/__init__.py +0 -0
- pywebguard/filters/base.py +44 -0
- pywebguard/filters/ip_filter.py +233 -0
- pywebguard/filters/user_agent.py +102 -0
- pywebguard/frameworks/__init__.py +0 -0
- pywebguard/frameworks/_fastapi.py +191 -0
- pywebguard/frameworks/_flask.py +182 -0
- pywebguard/limiters/__init__.py +0 -0
- pywebguard/limiters/base.py +46 -0
- pywebguard/limiters/rate_limit.py +415 -0
- pywebguard/logging/__init__.py +0 -0
- pywebguard/logging/backends/__init__.py +17 -0
- pywebguard/logging/backends/_elasticsearch.py +307 -0
- pywebguard/logging/backends/_meilisearch.py +310 -0
- pywebguard/logging/backends/_mongodb.py +303 -0
- pywebguard/logging/base.py +117 -0
- pywebguard/logging/logger.py +408 -0
- pywebguard/security/__init__.py +0 -0
- pywebguard/security/base.py +44 -0
- pywebguard/security/cors.py +204 -0
- pywebguard/security/penetration.py +265 -0
- pywebguard/storage/__init__.py +0 -0
- pywebguard/storage/_mongodb.py +396 -0
- pywebguard/storage/_postgresql.py +539 -0
- pywebguard/storage/_redis.py +314 -0
- pywebguard/storage/_sqlite.py +374 -0
- pywebguard/storage/_tinydb.py +271 -0
- pywebguard/storage/base.py +327 -0
- pywebguard/storage/memory.py +245 -0
- pywebguard/utils/__init__.py +0 -0
- pywebguard/utils/ip.py +84 -0
- pywebguard/utils/request.py +65 -0
- pywebguard-0.0.1.dist-info/LICENSE +21 -0
- pywebguard-0.0.1.dist-info/METADATA +434 -0
- pywebguard-0.0.1.dist-info/RECORD +43 -0
- pywebguard-0.0.1.dist-info/WHEEL +5 -0
- pywebguard-0.0.1.dist-info/entry_points.txt +2 -0
- pywebguard-0.0.1.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)
|