PyValentina a Python implementation of the core engine of Valentina


I hacked 6 month ago a Python implementation of the core engine of Valentina. I did the proof of concept in few hours and later implemented a cleaner code.

Example of generated layout for city trouser on A0 and tiled A4 paper:

Main purpose is to make patterns from an hacker point of view. Thus it is not for lambda users!

Also I believe Blender users could import 2D pattern geometries using this Python module and then use the Blender API to go to 3D.

It features actually:

  • read/write XML .val and .vit file
  • QMuParser expressions are translated to Python and evaluated on the fly
  • Python API to define patterns
  • compute the detail of a pattern
  • export the detail to LaTeX/PGF as A0 or tiled A4 paper

Missing features are:

  • full operation support: should be easy, maybe seam allowance would need more work
  • direct PDF export: easy using Qt Painter API for example
  • SVG export: cf. supra

API example:

Notice if you understand this, it can be faster to work with such code than using the Valentina GUI, simply because Valentina follow a WYSIWYG sequential approach, i.e. your pattern must be right at each action. Here it must only be right when you evaluate the code.

vit_file = VitFile(Path('patterns', 'measurements.vit'))
measurements = vit_file.measurements

pattern = Pattern(measurements, 'cm')

pattern.SinglePoint(name='A0', x=0.7, y=1.0))
pattern.EndLinePoint(name='A1', base_point='A0', angle=0, length='waist_circ/2+10', line_style='dashDotLine', line_color='black')
pattern.NormalPoint(name='A2', first_point='A0', second_point='A1', angle=180, length='leg_waist_side_to_floor+@longeur_ourlet_bas_pantalon', line_style='dashDotLine', line_color='black')
pattern.AlongLinePoint(name='A3', first_point='A0', second_point='A2', length=4, line_style='none', line_color='black')
pattern.AlongLinePoint(name='A4', first_point='A0', second_point='A2', length=20, line_style='none', line_color='black')
pattern.AlongLinePoint(name='A5', first_point='A0', second_point='A2', length='leg_waist_side_to_floor-@leg_crotch_to_floor_men', line_style='none', line_color='black')

How to get the code ?

Supporting Valentina in other "free" software; Hershy fonts (side issue)

Does Inkscape support Python?

I’d left a query in their bug tracker for an import filter (Bug #1714761 “Enhancement: Import filter/translator for Valentin...” : Bugs : Inkscape)

Of course if someone really clever worked out how to do run a python back-end to serve up an SVG or PNG thumbnail on the fly… :rofl: (See also: Proposal for parametric pattern support at Wikimedia Commons

In theory, and the willingness of someone to implement it a “Parametric Vector Graphic” format is starting to look entirely feasible :rofl:


A viewer extension for Inkscape (which uses python for extension scripts) is a separate topic. @alex.farlie if you want to discuss the creation of a viewer extension script for Inkscape, can you create a separate thread?


I will certainly consider doing so. Do you want the post here removed?


You don’t have to delete this one!



I tried to install PyValentina using ‘pip install PyValentina’ - but it seems that there is only a Python 3 Version.


@fabrice couple thoughts:

  • pretty awesome work!
  • why reimplement vs creating Python bindings into the C++ code?
  • I think it would be great to have bindings to other scripting languages too, ie JavaScript
  • it would also be awesome to transpile the core library (C++) to JS using Emsctipten, so it can be used in the browser or nodejs.


Hello, Python is an awesome language, but what is the intent of porting Valentina core to Python? Is it a first step toward a full Valentina implementation in Python? Strategically, would it be a good move? Python is known to be an easier and forgiving language (due to it being a dynamically typed and interpreted language), but also to have lower performance regarding execution speed (also due to it being a dynamically typed and interpreted language :slight_smile: ) ?


for those who understand pattern development and have less experience with programming, a simple way to think of the difference between python and C++ (or any dynamically typed and interpreted language vs most compiled, linked, and loaded languages) is that the lower performance can be a huge issue.

just like we had the discussion weeks ago with dismine who did not like the idea of an android version of tape, slow performance is a consideration.

in the 1980s there were those of us who delighted in re-using tiny code snippets in machine language and optimizing to save just one or two machine code operations. this was because computer memory was really limited and expensive. processing speed was also what we would consider today painfully slow. Over the last many years, processors have gotten faster and cheaper and the 16K of yesteryear has evolved into 8, 16, 32 G or more of memory.

I have heard Windows XP referred to as the 8086 emulator for the pentium. There is a reason for that.


Basically, the difference is ‘code fast’ vs ‘fast code’. Both are completely valid, depending on the situation. (As someone who coded graphics routines in 6502 assembly on the Apple ][, I understand where you are coming from. I can still remember my mind being blown when I found out that integers are now 32 or even 64(!) bits wide. OTOH, I blew the mind of the guy who told me by demonstrating that bit flags still have a valuable place even when you have 16GB of RAM. :grin: )


I can’t see why Tape in an Android app would have a speed issue… there’s multitrack DAW’s that work on Android that take a lot more processing that TAPE ever would.

“PC” processing power in 80’s was painfully slow… Amiga’s with 68030’s or 40’s were a dream to work with. Actually… the Intel chips were pretty fast when just doing computations, but the PC’s lacked the gfx co processors that made the Amiga’s fly. Well, that and the fact that the Amiga was a true pre-emptive multi tasking machine… something Windoze still can’t do.

In any case, at the time I use to write programs in AmigaBasic (ironically written by Microsoft) a typical run time interpreted Basic, but I would compile the source (with a few minor changes) with an open source Basic compiler. I wrote a few libraries and device drivers in assembly for functions that needed the speed… or sometimes would tweak the compiler’s asm output before linking to gain a few cycles. Later I switched from Basic to C.


I’m pretty sure that trained monkeys could write a python app that would run fast enough on pretty much any Android device. :cough:


and Qt supports android. So I am fairly sure once I figure out the entire build process it will be a no-brainer to add an android version


and if somebody figures out the build process before I do it will not bend my feelings in the least. I can always find something else to do :wink:


Theoretically you should be able to setup a build kit for Android and build.

I can see this being VERY useful for costume shops and Theatres… the wardrobe people could take measurements on their phone/tablet anywhere - based on MY needed measurements - and send them back via email.


There’s a phone measurement app that has been started but not finished:


Hey, I am trying to understand something, is this library only for reading vit files or we can create a pattern here itself and then transform it back to .vit extension and/or pdf format


Hey @anuj8826! The drafted pattern formulas are stored into an xml file with extension .val

The body measurements data is stored into an xml file with extension .vit

The pattern formulas create the drawing on the software canvas. The image drawn on the canvas can be exported to vector (svg, eps, hpgl, ps, dxf, pdf) and raster/bitmap (png, jpg).


Hey @slspencer, so I can’t create a pattern from scratch using just the Python library, PyValentina. Thanks for responding back. I am actually trying to get the below jobs done :

First create a pattern from scratch only using this library without using the software Valentina. Then finally export it back to SVG.


Ah, so it’s really a return to the prototype. I’ll have to think about this, my previous approach was to script each step, so that each design is a result of running a manually created python program against my patternmaking function library. And I wrote the library to contain functions which broke down each manual method from patternmaking into it’s 2D geometry equivalent, which required reducing advanced computer graphics math down to 10th grade “desktop” math (surprisingly this was not an easy task!) and creating a element factory to create the SVG objects needed for patternmaking (based on the SVG object W3 specs) – this all took about 2 years to accomplish in total, not including the previous 2 years studying the 50+ patternmakingmethods to derive the engineering first principles of patternmaking which had been lost over time and are no longer taught (if they ever truly were taught, typically the reasons why and assumptions behind each patternmaking step were just implied not discussed).

What you’re asking for is what Roman and I did to create Seamly2D/Valentina - we built a GUI around the library, and added a canvas to show interactively the results of each design/programming step.

So, I really think this is the way to go, away from C++ due to lack of available programmers, and get back to something (python?) we can all work on. But some people have suggested GO, as there are a lot of hungry GO programmers looking for a project right now to prove their chops. And GO doesn’t seem to be so difficult, it’s just new.

Whatever programming language we choose, it will still take time. Fortunately, the good people of this forum provided all the guidance as to what workflow is required, and what finishing steps are needed, to produce a software tool optimized for real custom professional patternmakers and tailors. Because of this forum, the product definition is almost complete even though the product development is not. Design is always more than half the battle with software.

Let’s keep this discussion going. Is there a reason you want PyValentina to generate a pattern, is there a business case or a personal project? I’m asking as a product manager, the more I know the more I can help you.