Skip to main content

A comprehensive QR Code Generator library with CLI, Streamlit UI, and robust testing

Project description

QR Code Generator in Python

A comprehensive Python application for generating QR codes with both command-line and web interfaces. Features include customizable output directories, multiple content types, comprehensive testing, and a user-friendly Streamlit web UI.

๐Ÿš€ Features

  • Easy to Use: Simple class-based interface for QR code generation
  • Web Interface: Modern Streamlit web UI for interactive QR code generation
  • Organized Output: Automatically saves all QR codes to designated output folders
  • Timestamp Naming: Automatic file naming with microsecond timestamps to prevent overwrites
  • Customizable Prefix: Set custom prefixes for generated QR code files
  • Customizable Output Directory: Choose where to save your QR code files
  • Multiple Content Types: Support for URLs, text, email, phone, WiFi, vCard, and custom content
  • High Quality: Optimized settings for clear, scannable QR codes
  • Comprehensive Testing: 96% test coverage with unit and integration tests
  • Cross-Platform: Works on Windows, Linux, and macOS
  • Professional Setup: Automated scripts for environment setup and management

## ๐Ÿงช Testing

Run the built-in example:

```bash
python QRCodeGenerator.py

This will create a QR code for the LinkedIn profile URL and save it in the output folder.

๐ŸŒ Streamlit Web Interface

Launch the interactive web interface:

# Using the provided script (recommended)
streamlit run streamlit_app.py

# Or using batch/shell scripts
scripts\windows\run_streamlit.bat    # Windows
scripts/unix/run_streamlit.sh        # Linux/Mac

The web interface provides:

  • Interactive Forms: Easy-to-use forms for different content types
  • Real-time Preview: See your QR code generated instantly
  • Download Support: Direct download of generated QR codes
  • Multiple Content Types: Support for URLs, text, email, phone, WiFi, vCard
  • Customizable Settings: Adjust file prefixes and output folders
  • Usage Statistics: Track QR codes generated in your session

๐Ÿ› ๏ธ Quick Setup Scripts

For easy environment management, use the provided scripts:

Windows (.bat files):

scripts\windows\setup_env.bat      # Create virtual environment
scripts\windows\activate.bat       # Activate environment and open interactive shell
scripts\windows\install_deps.bat   # Install all dependencies
scripts\windows\run_main.bat       # Run the main CLI application
scripts\windows\run_tests.bat      # Run unit tests with coverage
scripts\windows\run_coverage.bat   # Generate detailed coverage reports
scripts\windows\run_streamlit.bat  # Launch web interface

Linux/Mac (.sh files):

scripts/unix/setup_env.sh      # Create virtual environment
scripts/unix/activate.sh       # Activate environment and open interactive shell
scripts/unix/install_deps.sh   # Install all dependencies
scripts/unix/run_main.sh       # Run the main CLI application
scripts/unix/run_tests.sh      # Run unit tests with coverage
scripts/unix/run_coverage.sh   # Generate detailed coverage reports
scripts/unix/run_streamlit.sh  # Launch web interface

Running Unit Tests

The project includes comprehensive unit tests using pytest:

# Install test dependencies
pip install pytest pytest-cov

# Run all tests
pytest tests/ -v

# Run tests with coverage
pytest tests/ -v --cov=QRCodeGenerator --cov-report=term-missing

# Run only unit tests
pytest tests/test_qr_code_generator.py -v

# Run only integration tests
pytest tests/test_main_function.py -v

# Generate HTML coverage report
pytest tests/ --cov=QRCodeGenerator --cov-report=html:htmlcov

Using the Test Runner

You can also use the included test runner script:

# Run all tests with coverage
python run_tests.py --coverage

# Run tests with HTML coverage report
python run_tests.py --html-cov

# Run only unit tests
python run_tests.py --unit-only --verbose

# Run tests quickly (skip slow tests)
python run_tests.py --fast

Test Coverage

The project maintains high test coverage:

  • Unit Tests: Test individual components and methods
  • Integration Tests: Test complete workflows and main function
  • Edge Cases: Test error conditions and boundary cases
  • Parametrized Tests: Test multiple scenarios efficiently

Current test coverage: 96%-based naming to prevent file conflicts.

๐Ÿš€ Features

  • Easy to Use: Simple class-based interface for QR code generation
  • Organized Output: Automatically saves all QR codes to a designated output folder
  • Timestamp Naming: Automatic file naming with timestamps to prevent overwrites
  • Customizable Prefix: Set custom prefixes for generated QR code files
  • Customizable Output Directory: Choose where to save your QR code files
  • High Quality: Optimized settings for clear, scannable QR codes
  • Flexible Input: Supports any text, URLs, or string data
  • Zero Configuration: Works out of the box with sensible defaults

๐Ÿ“‹ Requirements

  • Python 3.12+
  • qrcode library
  • Pillow (PIL) for image handling

๐Ÿ› ๏ธ Installation

Using Poetry (Recommended)

# Clone the repository
git clone https://github.com/ShanKonduru/QRCodeGenPy.git
cd QRCodeGenPy

# Install dependencies using Poetry
poetry install

# Activate the virtual environment
poetry shell

Using pip

# Clone the repository
git clone https://github.com/ShanKonduru/QRCodeGenPy.git
cd QRCodeGenPy

# Install dependencies
pip install -r requirements.txt

Manual Installation

Install the required packages:

pip install qrcode[pil]

๐ŸŽฏ Quick Start

Basic Usage

from QRCodeGenerator import QRCodeGenerator

# Create a QR code generator instance (saves to 'output' folder by default)
generator = QRCodeGenerator()

# Generate a QR code for a URL
filename = generator.generate_qr_code("https://www.example.com")
print(f"QR code saved as: {filename}")
# Output: output/qr_code_20241001123456.png

Custom File Prefix and Output Folder

# Use a custom prefix and output folder
generator = QRCodeGenerator("my_website", "my_qr_codes")
filename = generator.generate_qr_code("https://www.mywebsite.com")
# Output: my_qr_codes/my_website_20241001123456.png

Running the Example

python QRCodeGenerator.py

This will generate a QR code for the LinkedIn profile URL and save it in the output folder.

๐Ÿ“– API Documentation

Class: QRCodeGenerator

Constructor

QRCodeGenerator(file_prefix="qr_code", output_folder="output")

Parameters:

  • file_prefix (str, optional): Prefix for the output filename. Defaults to "qr_code".
  • output_folder (str, optional): Directory to save QR code images. Defaults to "output".

Methods

generate_qr_code(input_string)

Generates a QR code from the provided input string and saves it as a PNG image in the specified output folder.

Parameters:

  • input_string (str): The text or URL to encode in the QR code.

Returns:

  • str: The full path of the generated QR code image (includes folder and .png extension).

Example:

generator = QRCodeGenerator()
filename = generator.generate_qr_code("Hello, World!")

๐Ÿ”ง QR Code Settings

The generated QR codes use the following optimized settings:

  • Version: 1 (21x21 modules)
  • Error Correction: Low (~7% error correction)
  • Box Size: 10 pixels per module
  • Border: 4 modules wide (minimum recommended)
  • Colors: Black foreground on white background

๐Ÿ“ Project Structure

QRCodeGenPy/
โ”œโ”€โ”€ QRCodeGenerator.py          # Main QR code generator class
โ”œโ”€โ”€ streamlit_app.py           # Streamlit web interface
โ”œโ”€โ”€ run_security_audit.py      # Security audit script
โ”œโ”€โ”€ run_tests.py              # Test runner script
โ”œโ”€โ”€ requirements.txt            # pip dependencies
โ”œโ”€โ”€ pyproject.toml             # Poetry configuration and PyPI metadata
โ”œโ”€โ”€ setup.py                  # PyPI setup script
โ”œโ”€โ”€ poetry.lock               # Poetry lock file
โ”œโ”€โ”€ pytest.ini               # Pytest configuration
โ”œโ”€โ”€ README.md                 # This documentation
โ”œโ”€โ”€ LICENSE                   # MIT license
โ”œโ”€โ”€ MANIFEST.in              # Package inclusion rules
โ”œโ”€โ”€ .env.example             # Environment variables template
โ”œโ”€โ”€ .gitignore               # Git ignore rules
โ”œโ”€โ”€ scripts/                  # Automation scripts
โ”‚   โ”œโ”€โ”€ windows/             # Windows batch files (.bat)
โ”‚   โ”‚   โ”œโ”€โ”€ setup_env.bat
โ”‚   โ”‚   โ”œโ”€โ”€ run_tests.bat
โ”‚   โ”‚   โ”œโ”€โ”€ upload_pypi.bat
โ”‚   โ”‚   โ””โ”€โ”€ ... (other .bat files)
โ”‚   โ”œโ”€โ”€ unix/                # Unix/Linux/Mac shell scripts (.sh)
โ”‚   โ”‚   โ”œโ”€โ”€ setup_env.sh
โ”‚   โ”‚   โ”œโ”€โ”€ run_tests.sh
โ”‚   โ”‚   โ”œโ”€โ”€ upload_pypi.sh
โ”‚   โ”‚   โ””โ”€โ”€ ... (other .sh files)
โ”‚   โ””โ”€โ”€ README.md            # Scripts documentation
โ”œโ”€โ”€ tests/                    # Test directory
โ”‚   โ”œโ”€โ”€ __init__.py          # Test package init
โ”‚   โ”œโ”€โ”€ test_qr_code_generator.py  # Unit tests
โ”‚   โ””โ”€โ”€ test_main_function.py     # Integration tests
โ”œโ”€โ”€ output/                   # Default QR code output directory
โ”‚   โ””โ”€โ”€ *.png                # Generated QR code files
โ”œโ”€โ”€ security_reports/         # Security audit reports
โ”‚   โ”œโ”€โ”€ bandit_report.json   # Bandit security scan
โ”‚   โ”œโ”€โ”€ pip_audit_report.json # pip-audit results
โ”‚   โ””โ”€โ”€ security_summary.md  # Audit summary
โ””โ”€โ”€ htmlcov/                  # Coverage report (generated)
    โ””โ”€โ”€ index.html           # HTML coverage report

๐ŸŽจ Examples

Generate QR Code for Different Types of Data

from QRCodeGenerator import QRCodeGenerator

# Create generator with custom prefix and output folder
generator = QRCodeGenerator("example", "my_qr_outputs")

# Website URL
website_qr = generator.generate_qr_code("https://www.github.com")
# Output: my_qr_outputs/example_20241001123456.png

# Contact information (vCard format)
contact_info = """BEGIN:VCARD
VERSION:3.0
FN:John Doe
ORG:Example Company
TEL:+1234567890
EMAIL:john@example.com
END:VCARD"""
contact_qr = generator.generate_qr_code(contact_info)

# WiFi connection info
wifi_info = "WIFI:T:WPA;S:MyNetworkName;P:MyPassword;;"
wifi_qr = generator.generate_qr_code(wifi_info)

# Plain text
text_qr = generator.generate_qr_code("Hello, QR Code World!")

# All files are saved in the 'my_qr_outputs' folder

๐Ÿงช Testing

Run the built-in example:

python QRCodeGenerator.py

This will create a QR code for the LinkedIn profile URL and display the filename.

๐Ÿค Contributing

  1. Fork the repository
  2. Create a feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add some amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

๏ฟฝ PyPI Publishing

Setup PyPI Credentials

  1. Copy the environment template:

    cp .env.example .env
    
  2. Edit .env file with your PyPI credentials:

    PYPI_USER_NAME=your_pypi_username
    PYPI_PASSWORD=your_pypi_password_or_token
    

    Recommended: Use an API token instead of your password. Generate one at: https://pypi.org/manage/account/token/

Upload to PyPI

Windows:

# Upload to PyPI (reads credentials from .env)
scripts\windows\upload_pypi.bat

Linux/Mac:

# Make script executable
chmod +x scripts/unix/upload_pypi.sh

# Upload to PyPI (reads credentials from .env)
scripts/unix/upload_pypi.sh

The upload script will:

  1. Run security audits
  2. Run all tests
  3. Build the package
  4. Upload to PyPI using credentials from .env

Installation from PyPI

Once published, users can install your package:

pip install qrcodegenpy-shankonduru

๐Ÿ”’ Security Auditing

Run comprehensive security audits with:

Windows:

scripts\windows\run_security_audit.bat

Linux/Mac:

scripts/unix/run_security_audit.sh

Security tools used:

  • safety - Checks for known vulnerabilities in dependencies
  • bandit - Scans Python code for security issues
  • pip-audit - Audits packages for known vulnerabilities

Reports are saved in security_reports/ folder.

๏ฟฝ๐Ÿ“„ License

This project is licensed under the MIT License - see the LICENSE file for details.

๐Ÿ‘จโ€๐Ÿ’ป Author

Shan Konduru

๐Ÿ™ Acknowledgments

  • qrcode library for QR code generation
  • Pillow for image processing
  • Python community for excellent documentation and examples

๐Ÿ“ˆ Version History

  • v1.0.0 - Major Release ๐ŸŽ‰

    • โœ… Complete project restructure with professional standards
    • โœ… Comprehensive testing suite (26 tests, 96% coverage)
    • โœ… Streamlit web interface for interactive QR generation
    • โœ… Security auditing with safety, bandit, and pip-audit
    • โœ… PyPI publishing automation with .env credential management
    • โœ… Cross-platform automation scripts (.bat and .sh)
    • โœ… HTML test reports and coverage analysis
    • โœ… Professional documentation and project structure
    • โœ… Git workflow integration and CI/CD ready
  • v0.1.0 - Initial Release

    • Basic QR code generation
    • Timestamp-based file naming
    • Customizable file prefixes
    • Basic documentation

Made with โค๏ธ by Shan Konduru

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

qrcodegenpy_shankonduru-1.0.0.tar.gz (9.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

qrcodegenpy_shankonduru-1.0.0-py3-none-any.whl (10.1 kB view details)

Uploaded Python 3

File details

Details for the file qrcodegenpy_shankonduru-1.0.0.tar.gz.

File metadata

  • Download URL: qrcodegenpy_shankonduru-1.0.0.tar.gz
  • Upload date:
  • Size: 9.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.7

File hashes

Hashes for qrcodegenpy_shankonduru-1.0.0.tar.gz
Algorithm Hash digest
SHA256 b9333119d5ab6269b0e4e2ac45bd760f50257bb07ce3913577d8e67f0169e822
MD5 2defa957e1c16990b25ad119512e1f96
BLAKE2b-256 9ebe513158fdef5e55e8495806411e93329c1fa678e200d761c64dbd357bd98d

See more details on using hashes here.

File details

Details for the file qrcodegenpy_shankonduru-1.0.0-py3-none-any.whl.

File metadata

File hashes

Hashes for qrcodegenpy_shankonduru-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 8a7baf13a25a0ca8b27efd959de18647da2e66d36ee3e95dddb93a613eb9cacf
MD5 682f613bbfc93437e8da793b51646666
BLAKE2b-256 c7c32ef5457d6227db2651a6f9f6ad18cadc7a0fd63aa12d9591161402bf0a4b

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page