samlibs-generate-password


Namesamlibs-generate-password JSON
Version 1.0.0 PyPI version JSON
download
home_pagehttps://github.com/themrsami/samlibs-generate-password-python
SummaryA lightweight, fast, and optimized password generator library for Python
upload_time2025-09-05 04:58:31
maintainerNone
docs_urlNone
authorthemrsami
requires_python>=3.6
licenseNone
keywords password generator random security lightweight fast samlibs cryptography
VCS
bugtrack_url
requirements build twine
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # samlibs-generate-password (Python)

[![PyPI version](https://badge.fury.io/py/samlibs-generate-password.svg)](https://badge.fury.io/py/samlibs-generate-password)
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
[![Python 3.6+](https://img.shields.io/badge/python-3.6+-blue.svg)](https://www.python.org/downloads/)

A **lightweight**, **fast**, and **optimized** password generator library for Python. Unlike other libraries that require complex setup, this package provides simple functions that accept configuration parameters to generate secure passwords.

## ๐Ÿš€ Features

- **Ultra Lightweight**: Zero dependencies and optimized code
- **Fast Performance**: Efficient character pool generation and selection
- **Type Hints**: Full type annotations for better IDE support
- **Cryptographically Secure**: Uses `secrets` module for secure random generation
- **Flexible API**: Both function parameters and dictionary-based configuration
- **Character Exclusion**: Exclude specific characters from password generation
- **Python 3.6+**: Compatible with modern Python versions

## ๐Ÿ“ฆ Installation

```bash
pip install samlibs-generate-password
```

## ๐Ÿ”ง Usage

### Basic Usage

```python
from samlibs_generate_password import generate_password

# Generate a simple password with default settings
password = generate_password()
print(password)  # e.g., "K9$mN7#qR2@x"

# Generate password with custom parameters
custom_password = generate_password(
    length=16,
    uppercase=True,
    lowercase=True,
    numbers=True,
    special=False,
    exclude=['0', 'O', 'l', '1']
)
print(custom_password)  # e.g., "KmN7qR2xPzWcJbVn"
```

### Dictionary API (Node.js Style)

```python
from samlibs_generate_password import generate_password_dict

# Generate password using dictionary configuration
password = generate_password_dict({
    'length': 20,
    'quantity': 1,
    'lowercase': True,
    'uppercase': True,
    'numbers': True,
    'special': True,
    'exclude': ['@', '#', '$']
})
print(password)
```

### Multiple Passwords

```python
# Generate multiple passwords
passwords = generate_password(length=12, quantity=5)
print(passwords)  # List of 5 passwords
```

### Type Hints Support

```python
from typing import List
from samlibs_generate_password import generate_password

# Type hints work perfectly
single_password: str = generate_password(quantity=1)
multiple_passwords: List[str] = generate_password(quantity=5)
```

## โš™๏ธ Function Parameters

### `generate_password()` Parameters

| Parameter | Type | Default | Description |
|-----------|------|---------|-------------|
| `length` | `int` | `12` | Length of each password |
| `quantity` | `int` | `1` | Number of passwords to generate |
| `lowercase` | `bool` | `True` | Include lowercase letters (a-z) |
| `uppercase` | `bool` | `True` | Include uppercase letters (A-Z) |
| `numbers` | `bool` | `True` | Include numbers (0-9) |
| `special` | `bool` | `True` | Include special characters (!@#$%^&*()_+-=[]{}|;:,.<>?) |
| `exclude` | `List[str]` | `None` | List of characters to exclude |

### Return Types

- **Single password** (`quantity=1`): Returns `str`
- **Multiple passwords** (`quantity>1`): Returns `List[str]`

## ๐Ÿ“‹ Examples

### Character Type Control

```python
# Only letters and numbers, 16 characters
password = generate_password(length=16, special=False)

# Only uppercase letters, 8 characters
password = generate_password(
    length=8,
    lowercase=False,
    numbers=False,
    special=False
)

# Only numbers, 6 characters (PIN-like)
pin = generate_password(
    length=6,
    lowercase=False,
    uppercase=False,
    special=False
)
```

### Exclude Similar Characters

```python
# Exclude confusing characters like 0, O, l, 1
password = generate_password(
    length=12,
    exclude=['0', 'O', 'l', '1', 'I']
)

# Database-safe password (no quotes or backslashes)
db_password = generate_password(
    length=32,
    special=False,
    exclude=['\\\\', '/', '"', "'", '`']
)
```

### Batch Generation

```python
# Generate 10 unique passwords
passwords = generate_password(length=15, quantity=10)
for i, pwd in enumerate(passwords, 1):
    print(f"Password {i}: {pwd}")
```

### Error Handling

```python
try:
    # This will raise ValueError
    password = generate_password(
        lowercase=False,
        uppercase=False,
        numbers=False,
        special=False
    )
except ValueError as e:
    print(f"Error: {e}")
    # Output: Error: At least one character set must be enabled
```

## ๐Ÿ”’ Security Features

- Uses Python's `secrets` module for cryptographically secure randomness
- No predictable patterns in password generation
- Efficient character pool filtering to prevent bias
- Secure random selection without replacement bias

## ๐Ÿš€ Performance

This library is optimized for:
- **Minimal memory footprint** - Zero dependencies
- **Fast character pool generation** - Efficient string operations
- **Optimized exclusion filtering** - Set-based operations for O(1) lookups
- **Bulk generation** - Efficient batch password creation

### Performance Benchmark

```python
import time
from samlibs_generate_password import generate_password

# Benchmark: Generate 10,000 passwords
start_time = time.time()
passwords = generate_password(length=12, quantity=10000)
end_time = time.time()

print(f"Generated 10,000 passwords in {(end_time - start_time)*1000:.2f}ms")
# Typical output: Generated 10,000 passwords in 45.67ms
```

## ๐Ÿ“Š Comparison with Other Libraries

```python
# Other password libraries
from other_lib import PasswordGenerator
generator = PasswordGenerator(length=12, uppercase=True, ...)
password = generator.generate()

# samlibs-generate-password (simpler and faster)
from samlibs_generate_password import generate_password
password = generate_password(length=12, uppercase=True, ...)
```

## ๐Ÿงช Testing

Run the comprehensive test suite:

```bash
cd samlibs-generate-password-python
python test.py
```

The test suite includes:
- โœ… 25 comprehensive test cases
- โœ… Error handling validation
- โœ… Performance benchmarks
- โœ… Randomness verification
- โœ… API compatibility tests

## ๐Ÿค Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

1. Fork the repository
2. Create a feature branch
3. Add tests for new functionality
4. Ensure all tests pass
5. Submit a pull request

## ๐Ÿ“„ License

MIT License - see [LICENSE](LICENSE) file for details.

## ๐Ÿ”— Links

- [PyPI package](https://pypi.org/project/samlibs-generate-password/)
- [GitHub repository](https://github.com/themrsami/samlibs-generate-password)
- [Documentation](https://github.com/themrsami/samlibs-generate-password#readme)

## ๐Ÿ†š Related Projects

- [samlibs-generate-password (Node.js)](https://www.npmjs.com/package/samlibs-generate-password) - The original JavaScript/TypeScript version

---

Made with โค๏ธ for Python developers who value simplicity and performance.

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/themrsami/samlibs-generate-password-python",
    "name": "samlibs-generate-password",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.6",
    "maintainer_email": null,
    "keywords": "password, generator, random, security, lightweight, fast, samlibs, cryptography",
    "author": "themrsami",
    "author_email": "usamanazir13@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/65/d1/b5eebc753b4cdd914b2a37d88c38d11aa6dfde049053f03c461c0d4d5c50/samlibs_generate_password-1.0.0.tar.gz",
    "platform": null,
    "description": "# samlibs-generate-password (Python)\r\n\r\n[![PyPI version](https://badge.fury.io/py/samlibs-generate-password.svg)](https://badge.fury.io/py/samlibs-generate-password)\r\n[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)\r\n[![Python 3.6+](https://img.shields.io/badge/python-3.6+-blue.svg)](https://www.python.org/downloads/)\r\n\r\nA **lightweight**, **fast**, and **optimized** password generator library for Python. Unlike other libraries that require complex setup, this package provides simple functions that accept configuration parameters to generate secure passwords.\r\n\r\n## \ud83d\ude80 Features\r\n\r\n- **Ultra Lightweight**: Zero dependencies and optimized code\r\n- **Fast Performance**: Efficient character pool generation and selection\r\n- **Type Hints**: Full type annotations for better IDE support\r\n- **Cryptographically Secure**: Uses `secrets` module for secure random generation\r\n- **Flexible API**: Both function parameters and dictionary-based configuration\r\n- **Character Exclusion**: Exclude specific characters from password generation\r\n- **Python 3.6+**: Compatible with modern Python versions\r\n\r\n## \ud83d\udce6 Installation\r\n\r\n```bash\r\npip install samlibs-generate-password\r\n```\r\n\r\n## \ud83d\udd27 Usage\r\n\r\n### Basic Usage\r\n\r\n```python\r\nfrom samlibs_generate_password import generate_password\r\n\r\n# Generate a simple password with default settings\r\npassword = generate_password()\r\nprint(password)  # e.g., \"K9$mN7#qR2@x\"\r\n\r\n# Generate password with custom parameters\r\ncustom_password = generate_password(\r\n    length=16,\r\n    uppercase=True,\r\n    lowercase=True,\r\n    numbers=True,\r\n    special=False,\r\n    exclude=['0', 'O', 'l', '1']\r\n)\r\nprint(custom_password)  # e.g., \"KmN7qR2xPzWcJbVn\"\r\n```\r\n\r\n### Dictionary API (Node.js Style)\r\n\r\n```python\r\nfrom samlibs_generate_password import generate_password_dict\r\n\r\n# Generate password using dictionary configuration\r\npassword = generate_password_dict({\r\n    'length': 20,\r\n    'quantity': 1,\r\n    'lowercase': True,\r\n    'uppercase': True,\r\n    'numbers': True,\r\n    'special': True,\r\n    'exclude': ['@', '#', '$']\r\n})\r\nprint(password)\r\n```\r\n\r\n### Multiple Passwords\r\n\r\n```python\r\n# Generate multiple passwords\r\npasswords = generate_password(length=12, quantity=5)\r\nprint(passwords)  # List of 5 passwords\r\n```\r\n\r\n### Type Hints Support\r\n\r\n```python\r\nfrom typing import List\r\nfrom samlibs_generate_password import generate_password\r\n\r\n# Type hints work perfectly\r\nsingle_password: str = generate_password(quantity=1)\r\nmultiple_passwords: List[str] = generate_password(quantity=5)\r\n```\r\n\r\n## \u2699\ufe0f Function Parameters\r\n\r\n### `generate_password()` Parameters\r\n\r\n| Parameter | Type | Default | Description |\r\n|-----------|------|---------|-------------|\r\n| `length` | `int` | `12` | Length of each password |\r\n| `quantity` | `int` | `1` | Number of passwords to generate |\r\n| `lowercase` | `bool` | `True` | Include lowercase letters (a-z) |\r\n| `uppercase` | `bool` | `True` | Include uppercase letters (A-Z) |\r\n| `numbers` | `bool` | `True` | Include numbers (0-9) |\r\n| `special` | `bool` | `True` | Include special characters (!@#$%^&*()_+-=[]{}|;:,.<>?) |\r\n| `exclude` | `List[str]` | `None` | List of characters to exclude |\r\n\r\n### Return Types\r\n\r\n- **Single password** (`quantity=1`): Returns `str`\r\n- **Multiple passwords** (`quantity>1`): Returns `List[str]`\r\n\r\n## \ud83d\udccb Examples\r\n\r\n### Character Type Control\r\n\r\n```python\r\n# Only letters and numbers, 16 characters\r\npassword = generate_password(length=16, special=False)\r\n\r\n# Only uppercase letters, 8 characters\r\npassword = generate_password(\r\n    length=8,\r\n    lowercase=False,\r\n    numbers=False,\r\n    special=False\r\n)\r\n\r\n# Only numbers, 6 characters (PIN-like)\r\npin = generate_password(\r\n    length=6,\r\n    lowercase=False,\r\n    uppercase=False,\r\n    special=False\r\n)\r\n```\r\n\r\n### Exclude Similar Characters\r\n\r\n```python\r\n# Exclude confusing characters like 0, O, l, 1\r\npassword = generate_password(\r\n    length=12,\r\n    exclude=['0', 'O', 'l', '1', 'I']\r\n)\r\n\r\n# Database-safe password (no quotes or backslashes)\r\ndb_password = generate_password(\r\n    length=32,\r\n    special=False,\r\n    exclude=['\\\\\\\\', '/', '\"', \"'\", '`']\r\n)\r\n```\r\n\r\n### Batch Generation\r\n\r\n```python\r\n# Generate 10 unique passwords\r\npasswords = generate_password(length=15, quantity=10)\r\nfor i, pwd in enumerate(passwords, 1):\r\n    print(f\"Password {i}: {pwd}\")\r\n```\r\n\r\n### Error Handling\r\n\r\n```python\r\ntry:\r\n    # This will raise ValueError\r\n    password = generate_password(\r\n        lowercase=False,\r\n        uppercase=False,\r\n        numbers=False,\r\n        special=False\r\n    )\r\nexcept ValueError as e:\r\n    print(f\"Error: {e}\")\r\n    # Output: Error: At least one character set must be enabled\r\n```\r\n\r\n## \ud83d\udd12 Security Features\r\n\r\n- Uses Python's `secrets` module for cryptographically secure randomness\r\n- No predictable patterns in password generation\r\n- Efficient character pool filtering to prevent bias\r\n- Secure random selection without replacement bias\r\n\r\n## \ud83d\ude80 Performance\r\n\r\nThis library is optimized for:\r\n- **Minimal memory footprint** - Zero dependencies\r\n- **Fast character pool generation** - Efficient string operations\r\n- **Optimized exclusion filtering** - Set-based operations for O(1) lookups\r\n- **Bulk generation** - Efficient batch password creation\r\n\r\n### Performance Benchmark\r\n\r\n```python\r\nimport time\r\nfrom samlibs_generate_password import generate_password\r\n\r\n# Benchmark: Generate 10,000 passwords\r\nstart_time = time.time()\r\npasswords = generate_password(length=12, quantity=10000)\r\nend_time = time.time()\r\n\r\nprint(f\"Generated 10,000 passwords in {(end_time - start_time)*1000:.2f}ms\")\r\n# Typical output: Generated 10,000 passwords in 45.67ms\r\n```\r\n\r\n## \ud83d\udcca Comparison with Other Libraries\r\n\r\n```python\r\n# Other password libraries\r\nfrom other_lib import PasswordGenerator\r\ngenerator = PasswordGenerator(length=12, uppercase=True, ...)\r\npassword = generator.generate()\r\n\r\n# samlibs-generate-password (simpler and faster)\r\nfrom samlibs_generate_password import generate_password\r\npassword = generate_password(length=12, uppercase=True, ...)\r\n```\r\n\r\n## \ud83e\uddea Testing\r\n\r\nRun the comprehensive test suite:\r\n\r\n```bash\r\ncd samlibs-generate-password-python\r\npython test.py\r\n```\r\n\r\nThe test suite includes:\r\n- \u2705 25 comprehensive test cases\r\n- \u2705 Error handling validation\r\n- \u2705 Performance benchmarks\r\n- \u2705 Randomness verification\r\n- \u2705 API compatibility tests\r\n\r\n## \ud83e\udd1d Contributing\r\n\r\nContributions are welcome! Please feel free to submit a Pull Request.\r\n\r\n1. Fork the repository\r\n2. Create a feature branch\r\n3. Add tests for new functionality\r\n4. Ensure all tests pass\r\n5. Submit a pull request\r\n\r\n## \ud83d\udcc4 License\r\n\r\nMIT License - see [LICENSE](LICENSE) file for details.\r\n\r\n## \ud83d\udd17 Links\r\n\r\n- [PyPI package](https://pypi.org/project/samlibs-generate-password/)\r\n- [GitHub repository](https://github.com/themrsami/samlibs-generate-password)\r\n- [Documentation](https://github.com/themrsami/samlibs-generate-password#readme)\r\n\r\n## \ud83c\udd9a Related Projects\r\n\r\n- [samlibs-generate-password (Node.js)](https://www.npmjs.com/package/samlibs-generate-password) - The original JavaScript/TypeScript version\r\n\r\n---\r\n\r\nMade with \u2764\ufe0f for Python developers who value simplicity and performance.\r\n",
    "bugtrack_url": null,
    "license": null,
    "summary": "A lightweight, fast, and optimized password generator library for Python",
    "version": "1.0.0",
    "project_urls": {
        "Bug Reports": "https://github.com/themrsami/samlibs-generate-password-python/issues",
        "Documentation": "https://github.com/themrsami/samlibs-generate-password-python#readme",
        "Homepage": "https://github.com/themrsami/samlibs-generate-password-python",
        "Source": "https://github.com/themrsami/samlibs-generate-password-python"
    },
    "split_keywords": [
        "password",
        " generator",
        " random",
        " security",
        " lightweight",
        " fast",
        " samlibs",
        " cryptography"
    ],
    "urls": [
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "d7de6bee318405dfcf4db75e3617928be40a4f15f55cfe279c67b9f0f79873f0",
                "md5": "3c90c5365145441e24dfb920b0ce28b5",
                "sha256": "07f9385ba0e234c39fd6bff4cc401abfea8c0df4dd0ff0f2868ba4d1b3cbeec3"
            },
            "downloads": -1,
            "filename": "samlibs_generate_password-1.0.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "3c90c5365145441e24dfb920b0ce28b5",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.6",
            "size": 7380,
            "upload_time": "2025-09-05T04:58:30",
            "upload_time_iso_8601": "2025-09-05T04:58:30.461406Z",
            "url": "https://files.pythonhosted.org/packages/d7/de/6bee318405dfcf4db75e3617928be40a4f15f55cfe279c67b9f0f79873f0/samlibs_generate_password-1.0.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "65d1b5eebc753b4cdd914b2a37d88c38d11aa6dfde049053f03c461c0d4d5c50",
                "md5": "d0243cd0aa71c92141f2a6e541c29e70",
                "sha256": "26a2c07927bb8db790a7af5dd4048608e347694502284e13fe988e071fb05691"
            },
            "downloads": -1,
            "filename": "samlibs_generate_password-1.0.0.tar.gz",
            "has_sig": false,
            "md5_digest": "d0243cd0aa71c92141f2a6e541c29e70",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.6",
            "size": 7348,
            "upload_time": "2025-09-05T04:58:31",
            "upload_time_iso_8601": "2025-09-05T04:58:31.956650Z",
            "url": "https://files.pythonhosted.org/packages/65/d1/b5eebc753b4cdd914b2a37d88c38d11aa6dfde049053f03c461c0d4d5c50/samlibs_generate_password-1.0.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2025-09-05 04:58:31",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "themrsami",
    "github_project": "samlibs-generate-password-python",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "requirements": [
        {
            "name": "build",
            "specs": [
                [
                    ">=",
                    "0.8.0"
                ]
            ]
        },
        {
            "name": "twine",
            "specs": [
                [
                    ">=",
                    "4.0.0"
                ]
            ]
        }
    ],
    "lcname": "samlibs-generate-password"
}
        
Elapsed time: 4.60555s