[Samba] python module

Rowland Penny rpenny at samba.org
Sat Apr 8 10:16:12 UTC 2023



On 08/04/2023 00:14, David Bear wrote:
> Thanks Rowland. I really appreciate your rapid responses and many years 
> of work helping the python community.
> To answer your question, I could wrap samba tool -- but I thought it 
> would be easier -- and more pythonic to keep the code pure python.
> 
> As for what chatgpt knows... for the curious I'll paste the relevant 
> responses below. Chat did suggest making calls to the samba-tool. I 
> thought things would go faster for the script if it didn't have to spawn 
> a new shell to execute samba-tool in.
> ---- now, on the chat answers..----
> 
> There are several Python libraries for interacting with Samba and Active 
> Directory, and the best library to use depends on your specific use case 
> and requirements. Here are some popular options:
> 
>  1.
> 
>     |samba-python|: This is the official Python bindings for Samba,
>     which allows you to use Samba's internal libraries and functions
>     from Python. This library is low-level and may require more
>     expertise in Samba to use effectively.
> 
>  2.
> 
>     |python-samba|: This is a higher-level Python module that provides
>     an object-oriented interface to Samba's internal libraries. It
>     includes modules for interacting with Active Directory, LDAP, SMB,
>     and more.
> 
>  3.
> 
>     |pysmb|: This is a Python module for interacting with SMB/CIFS file
>     servers, including Samba servers. It provides a simple API for
>     reading and writing files, browsing directories, and executing
>     commands on a remote server.
> 
>  4.
> 
>     |smbprotocol|: This is another Python module for working with
>     SMB/CIFS file servers, including Samba servers. It provides a
>     lower-level API for sending and receiving SMB messages and packets.
> 
> ==== NOTE the distinction between samba-python and python-samba =====
> ==== Here is the paragraph that caught my attention ===
> 
>     If you are looking for a high-level, object-oriented interface to
>     Samba and Active Directory, python-samba is probably the best
>     choice. It provides a comprehensive set of classes and methods for
>     interacting with Active Directory, including creating, modifying,
>     and deleting user accounts, groups, and more. If you only need to
>     interact with SMB/CIFS file shares, pysmb or smbprotocol may be more
>     appropriate.
> 
> 
>       Note that python-samba and samba-python require the Samba
>     libraries to be installed on your system, while pysmb and
>     smbprotocol do not.
> 
> 
> ======
> 
> Note that Debian does have a python3-samba package
> 
> ii  python3-samba                                 2:4.13.13+dfsg-1~deb11u5
> 
> and I can import that into python
> 
> But it does not have the samba.netcmd.user.create name ...


I am not convinced that ChatGPT is as smart as what people would like us 
to think it is.

Python3-samba does have 'create' in it, just not has you think (or 
ChatGPT thinks).

One of the files that python3-samba installs is:

/usr/lib/python3/dist-packages/samba/netcmd/user.py

This is what is used if you run 'samba-tool user .....'

Now 'samba-tool user' has a subcommand called 'create', which, if you 
examine the bottom of user.py, calls the 'cmd_user_add' class, does that 
help ?

I still think you are trying to recreate the wheel, unless you are also 
trying to incorporate a GUI.

Rowland





More information about the samba mailing list