🚀 Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more
Socket
Sign inDemoInstall
Socket

pysessionmanager

Package Overview
Dependencies
Maintainers
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

pysessionmanager

A Python session management library with support for session timeouts, password-protected sessions, and persistent storage to files or databases. Suitable for web, GUI, and console applications. Provides functionality to create, update, delete, and validate sessions, with optional security and expiration controls. Ideal for managing user sessions in various types of Python projects.

0.3.0
PyPI
Maintainers
1

Certainly! Below is a more detailed and comprehensive README.md for your PySessionManager library, which includes sections like installation, usage, features, and more.

PySessionManager

PySessionManager is an extensible session management library for Python, designed to work seamlessly with both command-line interface (CLI) and web applications. It provides an easy-to-use interface for managing sessions, including session creation, expiration (TTL), and optional password protection.

Table of Contents

  • Installation
  • Usage Example
  • Features
  • Session Management
  • Security Features
  • Customization
  • Contributing
  • License

Installation

You can install PySessionManager via pip:

pip install pysessionmanager

Usage Example

Here is a simple usage example of how to create and manage sessions using PySessionManager:

from pysessionmanager import SessionManager

# Initialize the SessionManager
sm = SessionManager()

# Add a session for a user
session_id = sm.add_session("user123")

# Print the session ID and its status
print("Session started with ID:", session_id)

# Check if the session is active
if sm.is_active(session_id):
    print(f"Session {session_id} is active.")
else:
    print(f"Session {session_id} has expired.")

Features

  • Session Creation & Expiration: Create and manage sessions with optional expiration based on time-to-live (TTL).
  • Password Protection: Secure sessions with password protection, which can be enabled or disabled.
  • Flexible Storage: Store sessions in files (JSON by default) or connect to a database for more advanced use cases.
  • Cross-Platform: Can be used in both CLI applications and web applications, such as with Flask or Django.
  • Session Retrieval: Easily retrieve session details by session ID or user ID.
  • Session Removal: Remove sessions manually or automatically based on expiration.

Session Management

Adding a Session

You can add a session for a user with the add_session() method:

session_id = sm.add_session("user123", duration_seconds=3600)

This will create a session with a 1-hour expiration (TTL).

Checking Active Sessions

To check whether a session is still active, you can use is_active():

if sm.is_active(session_id):
    print(f"Session {session_id} is active.")

Session Expiration

Sessions automatically expire based on the time-to-live (TTL) you set when creating the session. You can also manually remove a session with the remove_session() method:

sm.remove_session(session_id)

Security Features

Password-Protected Sessions

You can protect sessions with a password. This prevents unauthorized access to session data. To enable protection, pass a password when creating the session:

session_id = sm.add_session("user123", protected=True, password="securepassword")

To unlock a protected session, use the unlock_session() method:

sm.unlock_session("user123", password="securepassword")

Hashing Passwords

For security reasons, passwords are hashed before being stored. The library uses SHA-256 hashing to ensure that the password is not stored in plaintext.

Customization

PySessionManager can be customized to fit your application’s needs. Here are some options:

  • Session Timeout (TTL): You can specify the session duration when creating a session by adjusting the duration_seconds parameter.
  • Custom Storage: By default, sessions are stored in a JSON file. However, you can modify the storage method to store sessions in a database, cloud storage, or another system.
  • Session Protection: Enable or disable password protection for specific sessions based on your needs.

Contributing

Contributions are welcome! If you have a feature request, bug report, or want to contribute code, feel free to open an issue or submit a pull request.

  • Fork the repository.
  • Create a new branch for your feature or fix.
  • Make your changes and write tests if applicable.
  • Open a pull request.

License

PySessionManager is released under the MIT License.

Keywords

session management

FAQs

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts