Are there any libraries (preferably open-source) for parsing AutoCAD files (DWG or DXF)?
Don't think you will find anything better than DWGdirect. Look here
and specifically here:
Duplicate of (or at least related to) http://stackoverflow.com/questions/169390/open-source-cad-drawing-dwg-library-in-c/ & http://stackoverflow.com/questions/298622/net-cad-component-that-can-read-write-dxf-dwg-files/
There isn't anything available for parsing DWG for free that I would regard as reliable. The Open Design Alliance tends to be cheaper & runs on more OS's than AutoDesk's RealDWG offering. The ODA has a price-tier for startups who aren't yet shipping code - RealDWG doesn't. Both the ODA and AutoDesk offer support in forums - you have to be a member of the ODA but AutoDesk's forums are at http://discussion.autodesk.com/forums/ where you can join for free.
DXF is a text-file format (similar to XML) which you can parse with anything you like - if you know what you're looking for. You may have more luck with finding a library for that (I haven't looked into it) but that would involve conversion from DWG format. Note that there are various releases of the DXF format
You can try Autodesk's DWG Trueview (free) but it is an end-user viewer - it doesn't officially offer an API. Some people have had varying degree of success in the past automating it. I haven't tried myself & I strongly suspect the latest versions have been hardened against that.
Ultimately, if you are working for high-profile clients who are likely to insist on, or at least balk at the absence of 'official' AutoCAD libraries and the "Trusted DWG" BS that goes with it then you may need to invest in a membership of the Autodesk Developer Network.
As a long-time end user I can tell you the devs at the ODA are more responsive to bug reports than AutoCAD.