Is there way to get the graphics card details in python. please help me in achieving this

That comes from the OS and depends on what "graphic card details" means. If you just want to know what type of graphics card, use subprocess to run lspci and pipe the output to a file. You can then read the file and search for "graphic".

That comes from the OS and depends on what "graphic card details" means. If you just want to know what type of graphics card, use subprocess to run lspci and pipe the output to a file. You can then read the file and search for "graphic".

I like this command sudo lshw -html > myharware.html to get hardware information. Also check lshal 's output.

i need the following Graphics card details:
a)graphics card brand and its model
b) Driver on the graphics card
c) RAM of the card

I need to achieve this using python how can i?

HAL (see http://en.wikipedia.org/wiki/Hardware_abstraction_layer) knows about your graphic card, and HAL is cross platform. For example when I type the command lshal on my linux system, the output contains thousands of lines among which the following informations about my graphic card

udi = '/org/freedesktop/Hal/devices/pci_10de_3d0'
  info.linux.driver = 'nvidia'  (string)
  info.parent = '/org/freedesktop/Hal/devices/computer'  (string)
  info.product = 'C61 [GeForce 6150SE nForce 430]'  (string)
  info.subsystem = 'pci'  (string)
  info.udi = '/org/freedesktop/Hal/devices/pci_10de_3d0'  (string)
  info.vendor = 'nVidia Corporation'  (string)
  linux.hotplug_type = 2  (0x2)  (int)
  linux.subsystem = 'pci'  (string)
  linux.sysfs_path = '/sys/devices/pci0000:00/0000:00:0d.0'  (string)
  pci.device_class = 3  (0x3)  (int)
  pci.device_protocol = 0  (0x0)  (int)
  pci.device_subclass = 0  (0x0)  (int)
  pci.linux.sysfs_path = '/sys/devices/pci0000:00/0000:00:0d.0'  (string)
  pci.product = 'C61 [GeForce 6150SE nForce 430]'  (string)
  pci.product_id = 976  (0x3d0)  (int)
  pci.subsys_product_id = 29449  (0x7309)  (int)
  pci.subsys_vendor = 'Micro-Star International Co., Ltd.'  (string)
  pci.subsys_vendor_id = 5218  (0x1462)  (int)
  pci.vendor = 'nVidia Corporation'  (string)
  pci.vendor_id = 4318  (0x10de)  (int)

Now, some people have written code to obtain hal/dbus information from a python program (see http://lists.freedesktop.org/archives/hal/2005-January/001623.html). This could be a robust starting point. Learn how to use dbus from python and extract hal information in a cross platform way ! (note that I can't find the card's RAM)...

For example I found this link http://en.wikibooks.org/wiki/Python_Programming/Dbus and ran this code

import dbus
 
bus = dbus.SystemBus()
hal_manager_object = bus.get_object('org.freedesktop.Hal', '/org/freedesktop/Hal/Manager')
hal_manager_interface = dbus.Interface(hal_manager_object, 'org.freedesktop.Hal.Manager')
 
method = hal_manager_object.get_dbus_method('GetAllDevices', 'org.freedesktop.Hal.Manager')
print "\n".join(list(iter(method())))

The output is a list of devices. Here is a part of it

/org/freedesktop/Hal/devices/usb_device_46d_c31b_noserial_if1_logicaldev_input
/org/freedesktop/Hal/devices/computer_logicaldev_input_0
/org/freedesktop/Hal/devices/storage_serial_WDC_WD5000AAKS_00A7B2_WD_WCASY5083667
/org/freedesktop/Hal/devices/pnp_PNP0501_serial_platform_0
/org/freedesktop/Hal/devices/storage_serial_ST3200021A_4LJ17W1J
/org/freedesktop/Hal/devices/acpi_CPU0
/org/freedesktop/Hal/devices/acpi_CPU1
/org/freedesktop/Hal/devices/net_computer_loopback
/org/freedesktop/Hal/devices/computer_logicaldev_input_1
/org/freedesktop/Hal/devices/ppdev_parport0
/org/freedesktop/Hal/devices/pci_10de_3f6_scsi_host_0
/org/freedesktop/Hal/devices/pci_10de_3f6_scsi_host_scsi_host
/org/freedesktop/Hal/devices/pci_10de_3ec_scsi_host_0
/org/freedesktop/Hal/devices/pci_10de_3ec_scsi_host_scsi_host
/org/freedesktop/Hal/devices/usb_device_45e_cb_noserial_if0_logicaldev_input
/org/freedesktop/Hal/devices/pnp_PNP0c01
/org/freedesktop/Hal/devices/pnp_PNP0c02_2
/org/freedesktop/Hal/devices/pnp_PNP0c02_1
/org/freedesktop/Hal/devices/pnp_PNP0c02_0

With this, you are very close to finding your graphic card information. I read that you must select devices with a pci.device_class equal to 3 (0x3).

Here is how I finally solved the problem on my platform (Mandriva linux x86_64). If it works on other OSes, I'll put it in the code snippets.

# you need the module dbus-python

def get_graphic_card_properties():
    import dbus
    bus = dbus.SystemBus()
    hal_manager_object = bus.get_object('org.freedesktop.Hal', '/org/freedesktop/Hal/Manager')
    prop = 'pci.device_class'
    for device in hal_manager_object.get_dbus_method('GetAllDevices', 'org.freedesktop.Hal.Manager')():
        dev = bus.get_object('org.freedesktop.Hal', device)
        interface = dbus.Interface(dev, dbus_interface='org.freedesktop.Hal.Device')
        if interface.PropertyExists(prop):
            if interface.GetProperty(prop) == 3:
                # we return the properties of the first device in the list
                # with a pci.device_class == 3 (should check if several such devs...
                return interface.GetAllProperties()

dic = get_graphic_card_properties()

for key, value in dic.iteritems():
    print("%s : %s" %(key, value))
    
""" my output -->
pci.subsys_vendor : Micro-Star International Co., Ltd.
pci.subsys_product_id : 29449
pci.linux.sysfs_path : /sys/devices/pci0000:00/0000:00:0d.0
linux.hotplug_type : 2
info.subsystem : pci
info.parent : /org/freedesktop/Hal/devices/computer
pci.vendor : nVidia Corporation
info.vendor : nVidia Corporation
linux.sysfs_path : /sys/devices/pci0000:00/0000:00:0d.0
pci.device_protocol : 0
pci.device_subclass : 0
info.product : C61 [GeForce 6150SE nForce 430]
pci.vendor_id : 4318
info.udi : /org/freedesktop/Hal/devices/pci_10de_3d0
pci.product : C61 [GeForce 6150SE nForce 430]
info.linux.driver : nvidia
pci.product_id : 976
pci.subsys_vendor_id : 5218
pci.device_class : 3
linux.subsystem : pci
"""

Please post some feedback about execution on your system :)

Very useful links: http://webcvs.freedesktop.org/hal/hal/doc/spec/hal-spec.html?view=co#ov_hal_linux26 and http://www.freedesktop.org/wiki/Software/hal.

do we get dbus module for window.. i goolgled but i couldn't find dbus module for windows plz help me out

the above link is not working .. throws "problem loading page" error .. any other link or way to get that plz

the above link is not working .. throws "problem loading page" error .. any other link or way to get that plz

Yes, the link was working a few hours ago, I don't know what happened. You can google search 'dbus4win' to get more information...

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.