No project description provided
Project description
house.svg generated using PySVG by Claude-4-sonnet
PySVG
A Python library for creating SVG graphics with an intuitive API. PySVG allows you to programmatically generate SVG graphics using Python, making it easy to create vector graphics for web applications, data visualization, or any other use case requiring scalable vector graphics.
Features
PySVG provides a collection of basic components that can be used to create complex SVG graphics:
Line
Create straight lines with customizable properties.
Circle
Draw circles with specified radius and position.
Ellipse
Create elliptical shapes with different horizontal and vertical radii.
Rectangle
Draw rectangles and squares with customizable dimensions.
Content
Add text strings and images to your SVG graphics.
Polyline
Create complex curves and shapes using polylines.
Cell
Create a cell with text, image, or SVG content.
Matrix
Visualize list of lists (matrices) with various styling options.
The Matrix component also supports border styling with numbers or labels, making it perfect for visualizing game boards, chess positions, or any grid-based data that requires coordinate labeling.
Installation
pip install uv
uv pip install svg-python
Quick Start
All components are located in the pysvg/components directory. For detailed usage examples of each component, please check the corresponding examples in the examples directory.
For example, to generate a chess board image (chess_board.py):
from pysvg.components import Matrix, Circle, TextContent, Canvas
from pysvg.schema import AppearanceConfig, Color
# Create chess board data, first row and column as coordinate labels
chess_data = [
["", "A", "B", "C", "D", "E", "F", "G", "H", "I"],
["9", "X", ".", ".", ".", "X", ".", ".", ".", "."],
["8", ".", ".", ".", ".", ".", ".", ".", ".", "."],
["7", ".", "O", ".", "O", ".", ".", "X", ".", "."],
["6", ".", ".", ".", "X", ".", ".", ".", ".", "O"],
["5", "O", ".", "X", "O", "X", ".", ".", ".", "."],
["4", ".", "X", "O", "O", ".", "O", ".", ".", "."],
["3", ".", ".", "X", "O", "X", ".", ".", ".", "."],
["2", ".", ".", ".", "X", ".", ".", ".", ".", "."],
["1", ".", "O", ".", "O", ".", ".", "X", ".", "."],
]
black_stone = Circle(
appearance=AppearanceConfig(fill=Color("black"), stroke=Color("#333333"))
)
white_stone = Circle(
appearance=AppearanceConfig(fill=Color("white"), stroke=Color("#333333"))
)
# Set appearance for pieces and empty spaces
bg_appearance = AppearanceConfig(
fill=Color("#DEB887"),
stroke=Color("#8B4513"),
fill_opacity=0.85,
stroke_width=1.4,
stroke_opacity=0.85,
)
bgmap = {
"X": bg_appearance,
"O": bg_appearance,
".": bg_appearance,
}
elemap = {
"X": black_stone,
"O": white_stone,
".": TextContent(""),
}
matrix = Matrix(
data=chess_data,
element_map=elemap,
background_map=bgmap,
border_as_coord="upperleft",
coord_font_size=20,
coord_font_family="Times New Roman",
coord_font_color=Color("black"),
elem_locate_on_line=True,
)
canvas = Canvas(width=530, height=530)
canvas.add(matrix.move_by(30, 30))
canvas.save("chess_board.svg")
The resulted image is shown below:
Note
-
For ease of use, transform operations in PySVG are commutative. For example,
foo.rotate(p1).move(p2)is equivalent tofoo.move(p2).rotate(p1). This differs from standard SVG behavior because we automatically arrange transform attributes in a fixed order: translate, scale, rotate, skewX, and skewY. -
component.scale(..)in PySVG is different from the standard SVG scale method.- The standard SVG scale method scales the component from the left top corner, while this method scales the component from the center.
- We strictly scale according to the size of the graphic bounding box area, which is different from standard SVG
Contributing
This project is under active development. We welcome contributions of:
- New components to enrich the library
- Interesting drawing examples in the
appsdirectory - Any other improvements via Pull Requests
License
This project is licensed under the terms of the LICENSE file included in the repository.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file svg_python-0.0.11.tar.gz.
File metadata
- Download URL: svg_python-0.0.11.tar.gz
- Upload date:
- Size: 267.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.8.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8a3176506f801f3611c385e33f4446b535fd7f30df2a8292711735949b3b940a
|
|
| MD5 |
b6e1eba5b70225e52b469e9e6b3f3ed7
|
|
| BLAKE2b-256 |
d4a50f3e7f7b3f6fe90b8abe5387cd195e5c24b3b93a844da4aeb1ce83d42211
|
File details
Details for the file svg_python-0.0.11-py3-none-any.whl.
File metadata
- Download URL: svg_python-0.0.11-py3-none-any.whl
- Upload date:
- Size: 43.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.8.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
26b892384e9836b3387fc7076d8f958bb4c82e663be5b3c5c21a4e41165283eb
|
|
| MD5 |
b24be0caaabdd4b7f4a2982fd69ff7b7
|
|
| BLAKE2b-256 |
884f5cbe6665650ed6d3f7bc1d316c6d75f7cbc0dd46dda7b592bc352d7c14a4
|