I have a file with extension .dwg (AutoCAD), and I want to call that file from a Python console and present it on the web. Is there a module for the .dwg extension or some other solution?
-
How do you propose to present on web? – Gary Kerr Apr 14 '10 at 11:56
-
1do you mean converting dwg to an image or just uploading the file to the web? – Boris Gorelik Apr 14 '10 at 11:57
-
1I mean present into IFrame like a google maps. – Ballon Apr 14 '10 at 12:07
4 Answers
GNU LibreDWG (GitHub mirror) is the canonical answer in late 2021. Hilariously forked from the now defunct LibDWG project documented in ...wait for it Esperanto, LibreDWG:
- Optionally installs Python 3 bindings (enabled by default).
- Optionally installs DWG→DXF converters (enabled by default).
- Is unsurprisingly licensed under the GPL 3.0 (fine for web backends; less fine everywhere else).
- Supports almost the entirety of R2010+.
Seriously, it's hot. LibreDWG is the only sane choice that still matters. Let's embrace sanity, everybody.

- 9,789
- 5
- 38
- 52
-
I saw this library a while back and was hoping to use it just to read the dwg content, unfortunately I am unable to understand the installation process of this library since I am inexperienced. Is there any resource you can point to get my wheels rolling? – Juan Carlos Asuncion Mar 31 '22 at 01:57
The best format for displaying these online would (imo) definitely be SVG. Recent browsers support SVG rendering natively; older ones (think IE6) may require an SVG plugin
So your best bet is probably using a command line convert tool like cad2svg (this is a free linux command line tool) which converts the DWG files to SVG. You can easily do this that from your Python program (using subprocess
).

- 112,638
- 29
- 165
- 179
-
3"As of December 2012, I am no longer licensed to provide the freeware download." SAD – varun Feb 15 '19 at 11:02
It's not easy to get data just from .dwg file, but much more easier from a .dxf file. So I choose to convert a .dwg file to a .dxf file, and just handle the .dxf file. This is not fast, but it is also an alternative, since there is no other easy way to handle .dwg files.
The converter is at https://www.opendesign.com/guestfiles/TeighaFileConverter.
My OS is CentOS 6.5 (GCC 4.4.7), so I choose Teigha File Converter for Linux 64-bit (RPM).
#Install some qt5 lib
yum install -y qt5*
# If your libstdc++.so.6 has GLIBCXX>=15, you can pass the following three steps (using strings /usr/lib64/libstdc++.so.6 | grep GLIBCXX to find)
mv libstdc++.so.6.0.20 /usr/lib64/libstdc++.so.6.0.20
mv /usr/lib64/libstdc.so.6 /usr/lib64/libstdc.so.6.bk
ln /usr/lib64/libstdc++.so.6.0.20 /usr/lib64/libstdc.so.6
# Install TeighaFileConverter
rpm -i --nodeps TeighaFileConverter_QT5_lnxX64_4.7dll.rpm
If you want to use the graphical interface, you need to install Qt 5, or you can just use it in terminal or use it as shell commands in your program.
TeighaFileConverter 'input_folder' 'output_folder' "output_version" "output_type" "recurse_folder" "audit" -platform offscreen
# 'input_folder' can't be same with output_folder
# For example, convert dwg to dxf
TeighaFileConverter ./ ./dxf "ACAD10" "DXF" "0" "0" -platform offscreen

- 30,738
- 21
- 105
- 131

- 29
- 1
Maybe there will be something you can use from this Summer Of Code project

- 295,403
- 53
- 369
- 502