qraft-cli 0.1.0__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.
qraft/__init__.py ADDED
@@ -0,0 +1 @@
1
+ __version__ = "0.1.0"
qraft/cli.py ADDED
@@ -0,0 +1,166 @@
1
+ import typer
2
+
3
+ from pathlib import Path
4
+ from rich.console import Console
5
+ from rich.panel import Panel
6
+ from rich import print
7
+
8
+ from qraft.generator import generate_qr
9
+
10
+ app = typer.Typer(
11
+ name="qraft",
12
+ help="A customizable QR code generator.",
13
+ no_args_is_help=True,
14
+ )
15
+
16
+ console = Console()
17
+
18
+
19
+ @app.command()
20
+ def create(
21
+ data: str = typer.Argument(
22
+ ...,
23
+ help="Text or URL to encode.",
24
+ ),
25
+ output: Path = typer.Option(
26
+ Path("output/qr.png"),
27
+ "--output",
28
+ "-o",
29
+ help="Output image path.",
30
+ ),
31
+ foreground: str = typer.Option(
32
+ "#000000",
33
+ "--color",
34
+ "-c",
35
+ help="QR foreground color.",
36
+ ),
37
+ background: str = typer.Option(
38
+ "#FFFFFF",
39
+ "--background",
40
+ "-b",
41
+ help="QR background color.",
42
+ ),
43
+ box_size: int = typer.Option(
44
+ 10,
45
+ "--size",
46
+ "-s",
47
+ min=1,
48
+ help="QR module size.",
49
+ ),
50
+ border: int = typer.Option(
51
+ 4,
52
+ "--border",
53
+ min=4,
54
+ help="QR border width.",
55
+ ),
56
+ correction: str = typer.Option(
57
+ "H",
58
+ "--correction",
59
+ "-e",
60
+ help="Error correction: L, M, Q or H.",
61
+ ),
62
+ style: str = typer.Option(
63
+ "square",
64
+ "--style",
65
+ help="QR style: square, rounded or circle.",
66
+ ),
67
+ logo: Path | None = typer.Option(
68
+ None,
69
+ "--logo",
70
+ help="Optional center logo.",
71
+ exists=True,
72
+ dir_okay=False,
73
+ readable=True,
74
+ ),
75
+ ):
76
+ """Generate a customizable QR code."""
77
+
78
+ try:
79
+ result = generate_qr(
80
+ data=data,
81
+ output=str(output),
82
+ foreground=foreground,
83
+ background=background,
84
+ box_size=box_size,
85
+ border=border,
86
+ error_correction=correction.upper(),
87
+ style=style.lower(),
88
+ logo=str(logo) if logo else None,
89
+ )
90
+
91
+ console.print(
92
+ Panel(
93
+ f"[bold green]QR code generated successfully![/bold green]\n\n"
94
+ f"Saved to: [cyan]{result}[/cyan]",
95
+ title="Qraft",
96
+ border_style="green",
97
+ )
98
+ )
99
+
100
+ except (ValueError, FileNotFoundError) as error:
101
+ console.print(f"[bold red]Error:[/bold red] {error}")
102
+ raise typer.Exit(code=1)
103
+
104
+
105
+ @app.command()
106
+ def interactive():
107
+ """Generate a QR code using interactive prompts."""
108
+
109
+ console.print(
110
+ Panel(
111
+ "[bold cyan]Welcome to Qraft![/bold cyan]\n"
112
+ "Create your own customizable QR code.",
113
+ border_style="cyan",
114
+ )
115
+ )
116
+
117
+ data = typer.prompt("Enter your URL or text")
118
+
119
+ foreground = typer.prompt(
120
+ "Foreground color",
121
+ default="#000000",
122
+ )
123
+
124
+ background = typer.prompt(
125
+ "Background color",
126
+ default="#FFFFFF",
127
+ )
128
+
129
+ style = typer.prompt(
130
+ "Style (square/rounded/circle)",
131
+ default="square",
132
+ )
133
+
134
+ correction = typer.prompt(
135
+ "Error correction (L/M/Q/H)",
136
+ default="H",
137
+ )
138
+
139
+ output = typer.prompt(
140
+ "Output path",
141
+ default="output/qr.png",
142
+ )
143
+
144
+ logo = typer.prompt(
145
+ "Logo path (leave empty to skip)",
146
+ default="",
147
+ )
148
+
149
+ try:
150
+ result = generate_qr(
151
+ data=data,
152
+ output=output,
153
+ foreground=foreground,
154
+ background=background,
155
+ style=style.lower(),
156
+ error_correction=correction.upper(),
157
+ logo=logo or None,
158
+ )
159
+
160
+ console.print(
161
+ f"\n[bold green]Success![/bold green] QR saved to {result}"
162
+ )
163
+
164
+ except (ValueError, FileNotFoundError) as error:
165
+ console.print(f"[bold red]Error:[/bold red] {error}")
166
+ raise typer.Exit(code=1)
qraft/generator.py ADDED
@@ -0,0 +1,148 @@
1
+ import qrcode
2
+
3
+ from pathlib import Path
4
+ from PIL import Image, ImageColor
5
+
6
+ from qrcode.constants import (
7
+ ERROR_CORRECT_L,
8
+ ERROR_CORRECT_M,
9
+ ERROR_CORRECT_Q,
10
+ ERROR_CORRECT_H,
11
+ )
12
+
13
+ from qrcode.image.styledpil import StyledPilImage
14
+ from qrcode.image.styles.colormasks import SolidFillColorMask
15
+ from qrcode.image.styles.moduledrawers import (
16
+ SquareModuleDrawer,
17
+ RoundedModuleDrawer,
18
+ CircleModuleDrawer,
19
+ )
20
+
21
+
22
+ ERROR_LEVELS = {
23
+ "L": ERROR_CORRECT_L,
24
+ "M": ERROR_CORRECT_M,
25
+ "Q": ERROR_CORRECT_Q,
26
+ "H": ERROR_CORRECT_H,
27
+ }
28
+
29
+ MODULE_STYLES = {
30
+ "square": SquareModuleDrawer,
31
+ "rounded": RoundedModuleDrawer,
32
+ "circle": CircleModuleDrawer,
33
+ }
34
+
35
+
36
+ def generate_qr(
37
+ data: str,
38
+ output: str = "output/qr.png",
39
+ foreground: str = "#000000",
40
+ background: str = "#FFFFFF",
41
+ box_size: int = 10,
42
+ border: int = 4,
43
+ error_correction: str = "H",
44
+ style: str = "square",
45
+ logo: str | None = None,
46
+ ):
47
+ """
48
+ Generate a customizable QR code.
49
+
50
+ Args:
51
+ data: Text or URL to encode.
52
+ output: Output image path.
53
+ foreground: QR foreground color.
54
+ background: QR background color.
55
+ box_size: Size of each QR module.
56
+ border: QR border width.
57
+ error_correction: L, M, Q or H.
58
+ style: square, rounded or circle.
59
+ logo: Optional path to a center logo.
60
+ """
61
+
62
+ if not data.strip():
63
+ raise ValueError("QR content cannot be empty.")
64
+
65
+ if error_correction not in ERROR_LEVELS:
66
+ raise ValueError("Invalid error correction level.")
67
+
68
+ if style not in MODULE_STYLES:
69
+ raise ValueError("Invalid QR style.")
70
+
71
+ if box_size < 1:
72
+ raise ValueError("Box size must be positive.")
73
+
74
+ if border < 4:
75
+ raise ValueError("Border should be at least 4 modules.")
76
+
77
+ qr = qrcode.QRCode(
78
+ version=None,
79
+ error_correction=ERROR_LEVELS[error_correction],
80
+ box_size=box_size,
81
+ border=border,
82
+ )
83
+
84
+ qr.add_data(data)
85
+ qr.make(fit=True)
86
+
87
+ image = qr.make_image(
88
+ image_factory=StyledPilImage,
89
+ module_drawer=MODULE_STYLES[style](),
90
+ color_mask=SolidFillColorMask(
91
+ front_color=ImageColor.getrgb(foreground),
92
+ back_color=ImageColor.getrgb(background),
93
+ ),
94
+ )
95
+
96
+ image = image.convert("RGB")
97
+
98
+ if logo:
99
+ image = add_logo(image, logo)
100
+
101
+ output_path = Path(output)
102
+ output_path.parent.mkdir(parents=True, exist_ok=True)
103
+
104
+ image.save(output_path)
105
+
106
+ return output_path
107
+
108
+
109
+ def add_logo(image: Image.Image, logo_path: str) -> Image.Image:
110
+ """Add a small logo in the center of the QR code."""
111
+
112
+ logo_file = Path(logo_path)
113
+
114
+ if not logo_file.is_file():
115
+ raise FileNotFoundError(f"Logo not found: {logo_path}")
116
+
117
+ logo = Image.open(logo_file).convert("RGBA")
118
+
119
+ qr_width, qr_height = image.size
120
+
121
+ # Keep the logo relatively small for scan reliability.
122
+ max_size = int(min(qr_width, qr_height) * 0.18)
123
+
124
+ logo.thumbnail((max_size, max_size), Image.Resampling.LANCZOS)
125
+
126
+ # Add a white background behind the logo.
127
+ padding = max(8, int(max_size * 0.12))
128
+
129
+ logo_background = Image.new(
130
+ "RGB",
131
+ (logo.width + padding * 2, logo.height + padding * 2),
132
+ "white",
133
+ )
134
+
135
+ logo_background.paste(
136
+ logo,
137
+ (padding, padding),
138
+ logo,
139
+ )
140
+
141
+ position = (
142
+ (qr_width - logo_background.width) // 2,
143
+ (qr_height - logo_background.height) // 2,
144
+ )
145
+
146
+ image.paste(logo_background, position)
147
+
148
+ return image
qraft/main.py ADDED
@@ -0,0 +1,4 @@
1
+ from qraft.cli import app
2
+
3
+ if __name__ == "__main__":
4
+ app()
@@ -0,0 +1,57 @@
1
+ Metadata-Version: 2.4
2
+ Name: qraft-cli
3
+ Version: 0.1.0
4
+ Summary: A customizable QR code generator built with Python.
5
+ License-Expression: MIT
6
+ Requires-Python: >=3.10
7
+ Description-Content-Type: text/markdown
8
+ License-File: LICENSE
9
+ Requires-Dist: qrcode[pil]>=8.0
10
+ Requires-Dist: Pillow>=10.0
11
+ Requires-Dist: typer>=0.12
12
+ Requires-Dist: rich>=13.0
13
+ Provides-Extra: dev
14
+ Requires-Dist: pytest>=8.0; extra == "dev"
15
+ Dynamic: license-file
16
+
17
+ # Qraft
18
+
19
+ A customizable QR code generator built with Python.
20
+
21
+ ## Features
22
+
23
+ - Generate QR codes from URLs and text.
24
+ - Customize foreground and background colors.
25
+ - Add logos to QR codes.
26
+ - Choose different QR module styles.
27
+ - Configure error correction levels.
28
+ - Interactive CLI.
29
+ - Export QR codes as PNG images.
30
+
31
+ ## Installation
32
+
33
+ ```bash
34
+ git clone YOUR_REPOSITORY_URL
35
+ cd qraft
36
+
37
+ python -m venv .venv
38
+ pip install -e ".[dev]"
39
+ ```
40
+
41
+ ## Usage
42
+
43
+ ```bash
44
+ qraft create "https://github.com"
45
+ qraft interactive
46
+ ```
47
+
48
+ ## Technologies
49
+ - Python
50
+ - qrcode
51
+ - Pillow
52
+ - Typer
53
+ - Rich
54
+ - Pytest
55
+
56
+ ## License
57
+ MIT
@@ -0,0 +1,10 @@
1
+ qraft/__init__.py,sha256=Pru0BlFBASFCFo7McHdohtKkUtgMPDwbGfyUZlE2_Vw,21
2
+ qraft/cli.py,sha256=LgvbVGZ-LeferqBOF14nctDQWwK_7QQbX51gUQ7Risw,3961
3
+ qraft/generator.py,sha256=XIgsD3TrYZ4RErD0O8PJ95RczaSt3DFf7WD7QLLU9YM,3683
4
+ qraft/main.py,sha256=MRn74bPbXIVDt1YRQjCG_S9OaXhSppIs8YyuzAM_fL8,66
5
+ qraft_cli-0.1.0.dist-info/licenses/LICENSE,sha256=GXk4ZC_-cxBiRy7lxLXBMZcy7UTvvhp_L3nrpFXldqY,1100
6
+ qraft_cli-0.1.0.dist-info/METADATA,sha256=WYcIPE1Q7hgGbO3aFLNMfOzrmx6yveHH60G5gT1Pdi4,1066
7
+ qraft_cli-0.1.0.dist-info/WHEEL,sha256=mOdXR9C3wMVov7cSY8PY-XCzo3SmmWCHvGQr5csJoao,91
8
+ qraft_cli-0.1.0.dist-info/entry_points.txt,sha256=FVCg7GHsNlZNm2qBTlO8bx1wCHXMBeYKaMLnSm4hNfc,41
9
+ qraft_cli-0.1.0.dist-info/top_level.txt,sha256=3hU55WE-jnf3XSp498P7UAJ7MrjoTn59LGi3tE5Ct3k,6
10
+ qraft_cli-0.1.0.dist-info/RECORD,,
@@ -0,0 +1,5 @@
1
+ Wheel-Version: 1.0
2
+ Generator: setuptools (84.2.1)
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any
5
+
@@ -0,0 +1,2 @@
1
+ [console_scripts]
2
+ qraft = qraft.main:app
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Andreea Patrascu-Udrea
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1 @@
1
+ qraft