🔐 Secure Network
A powerful and flexible networking extension for Python with built-in authentication, encryption, and HMAC security.
🚀 Features
✅ Secure authentication with bcrypt and Multi-Factor Authentication (MFA).
✅ Encrypted communication using HMAC verification.
✅ Rate-limiting to prevent brute force attacks.
✅ Event-driven architecture for handling network interactions.
✅ Supports both authenticated and unauthenticated connections.
📦 Installation
Install Secure Network via PyPI:
pip install secure_network
⚡ Quick Start
1️⃣ Secure Authentication Server & Client
For authenticated connections, use the SERVER and CLIENT classes:
import secure_network
# 🔹 Initialize the server
server = secure_network.SERVER(
key=None, hmac_key=None,
address=("0.0.0.0", 12345),
on_event=lambda event: print(event),
max_clients=10
)
# 🔹 Set the accounts file (default: accounts.json)
server.accounts_file = "accounts.json"
# 🔹 All MFA methods requires a sender!
server.GMAIL["gmail"] = "creatorGmail@example.com"
server.GMAIL["password"] = "YourPassword"
server.TEXT_LOCAL_API = "TEXT_LOCAL_API"
# 🔹 Create user accounts
server.create_account("admin", "adminpass", role="admin")
server.create_account("user", "userpass", role="user", mfa_method="email", contact="user@example.com")
# 🔹 Initialize client
client = secure_network.CLIENT(
key=None, hmac_key=None,
address=("127.0.0.1", 12345),
on_event=lambda event: print(event)
)
# 🚀 Start server and client
server.init()
client.init()
2️⃣ Basic Server & Client (Without Authentication)
If authentication isn't needed, use the Server and Client classes directly:
import secure_network
# 🔹 Initialize server
server = secure_network.Server(
key=None, hmac_key=None,
address=("0.0.0.0", 12345),
on_event=lambda event: print(event),
max_clients=10
)
# 🔹 Initialize client
client = secure_network.Client(
key=None, hmac_key=None,
address=("127.0.0.1", 12345),
on_event=lambda event: print(event)
)
# 🚀 Start server and client
server.init()
client.init()
🎯 Handling Events
Events provide real-time feedback about network status. You can handle them like this:
import secure_network
def on_event(event: secure_network.Event):
if event.type == secure_network.EventType.CONNECTION_REQUEST:
event.accept() # ✅ Accept connection
elif event.type == secure_network.EventType.CONNECTION_SUCCESS:
print(f"✅ Client connected: {event.data['address']}")
elif event.type == secure_network.EventType.RECEIVED:
print(f"📩 Received data: {event.data['data']}")
else:
print(f"ℹ️ Event: {event.type.id} - {event.type.description}")
# Generate secure keys
KEY, HMAC_KEY = secure_network.generate_key(), secure_network.generate_hmac_key()
# Create server
server = secure_network.Server(
key=KEY, hmac_key=HMAC_KEY,
address=("0.0.0.0", 12345),
on_event=on_event,
max_clients=10
)
# 🚀 Start server
server.init()
# Keep server running
while server.active:
pass
🔥 Event Types
Secure Network provides several event types for handling different network interactions:
| Event Type | Description | Data Fields |
|---|---|---|
CONNECTION_REQUEST |
Someone is trying to connect | {address, connection} (can accept/reject) |
CONNECTION_SUCCESS |
A client has successfully connected | {address, connection} |
CONNECTED |
The client/server has started communication | {} |
DISCONNECTED |
A client/server has disconnected | {} |
RECEIVED |
Data received from a device | {address, connection, data} |
THREAD_WARNING |
A thread did not behave as expected | {thread} |
ERROR |
An error occurred | {exception} |
ℹ️ Additional Information
- event.data contains event-specific details (e.g., client address, message data).
- event.accept() and event.reject() can be used for CONNECTION_REQUEST events.
- Addresses and connections appear only on the server side (clients do not see them).
📜 License
This project is licensed under the MIT License.
⭐ Like This Project?
If you find this useful, consider starring it on GitHub and contributing to its development! 🚀
Fixes...
- I've fixed many buggs and some simple best practises (further improvement)
- Fixed so data comes with the "PacketSizeError".
- Fixed README and much else.
- Implemented "passphrase" systems, so now you can easily implement passwords to represent different keys for both the fernet, and HMAC keys.
- Errors are implemented without directly accessing the network module or fernet.
- Further updates will be covered here...
Metadata
Release files for secure-network 1.0.13
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| secure_network-1.0.13.tar.gz | 15.1 kB | Without provenance | Details for secure_network-1.0.13.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| secure_network-1.0.13-py3-none-any.whl | Python 3 | none | any | Details for secure_network-1.0.13-py3-none-any.whl |
Total release size: 29.8 kB
Release files / secure_network-1.0.13.tar.gz
| Download URL | secure_network-1.0.13.tar.gz |
|---|---|
| Size | 15.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
58b382744d384c8c9fc639638a5f4bf7ccdb30da7332acd3e9e057300888f409
|
|
BLAKE2b-256 checksum How to use checksums |
232165a9b25b22584889e7fcdd7e0d377c052b8373ba8d3b456dc7fb40ce573f
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.13.1
|
Release files / secure_network-1.0.13-py3-none-any.whl
| Download URL | secure_network-1.0.13-py3-none-any.whl |
|---|---|
| Size | 14.7 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
02a4f8e51ef0af6c6a6a2487a290438d1e8b0bd22938794fe530ee4e96e5f626
|
|
BLAKE2b-256 checksum How to use checksums |
39beed5bf5d65256081ef205296cf78ee2e9ff0e17aeb73187f47f09f5e7fa0e
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.13.1
|
Security for secure-network 1.0.13
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.