Python bindings for libsmbclient

pip install pysmbc==1.0.23


SMB bindings for Python

PyPI Build Status GitHub license

These Python bindings are intended to wrap the libsmbclient API.


Currently libsmbclient 3.2.x or later is required. Ubuntu Example:

# sudo apt install build-essential pkg-config smbclient libsmbclient libsmbclient-dev python-dev

Or python3-dev instead of python-dev depending on your needs.


# make


To run Python tests in tests/ you need python-nose See nose documentation

To run all the tests execute

# nosetests

To run just one test, use

# nosetests

To selectively run test methods, printing output to console

# nosetests -vs

NOTE: to run your tests, you need

  • a running samba server
  • one shared folder with
    • rw permissions
    • guest ok = no


Directory listing

>>> import smbc
>>> ctx = smbc.Context (auth_fn=my_auth_callback_fn)
>>> entries = ctx.opendir ("smb://SERVER").getdents ()
>>> for entry in entries:
...     print entry
<smbc.Dirent object "music" (File share) at 0x7fbd7c42b3a0>
<smbc.Dirent object "IPC$" (IPC share) at 0x7fbd7c42b148>
<smbc.Dirent object "Charlie" (Printer share) at 0x7fbd7c42b3c8>
>>> d = ("smb://SERVER/music")

Shared Printer Listing

>>> import smbc
>>> ctx = smbc.Context()
>>> ctx.optionNoAutoAnonymousLogin = True
>>> ctx.functionAuthData = lambda se, sh, w, u, p: (domain_name, domain_username, domain_password)
>>> uri = 'smb://' + smb_server
>>> shared_printers = []
>>> entries = ctx.opendir(uri).getdents()
>>> 	for entry in entries:
>>> 		if entry.smbc_type == 4:
>>> 			shared_printers.append(

Write file

>>> import smbc
>>> import os
>>> ctx = smbc.Context (auth_fn=my_auth_callback_fn)
>>> file = ("smb://SERVER/music/file.txt", os.O_CREAT | os.O_WRONLY)
>>> file.write ("hello")

Read file

>>> import smbc
>>> ctx = smbc.Context (auth_fn=my_auth_callback_fn)
>>> file = ("smb://SERVER/music/file.txt")
>>> print