How to upload a .pyd file format onto the server?

Joel 1 Reputation point
2021-06-22T06:48:10.753+00:00

Hi,

I'm new to SQL Machine Learning Server and also quite new to Python.

Currently my company is acquiring SQL Machine Learning Server to deploy AI models onto the server. The AI Model that i am working on right now is being developed by an external vendor, and that vendor only provide me their model wrapped in a ".pyd" file or executable file in ".pyd" format to keep the codes encrypted. To use the model, i simply call the model by importing its function/method.

So the question is... how do i upload the ".pyd" file onto the server?

SQL Server
SQL Server
A family of Microsoft relational database management and analysis systems for e-commerce, line-of-business, and data warehousing solutions.
13,361 questions
SQL Server Analysis Services
SQL Server Analysis Services
A Microsoft online analytical data engine used in decision support and business analytics, providing the analytical data for business reports and client applications such as Power BI, Excel, Reporting Services reports, and other data visualization tools.
1,263 questions
{count} votes

2 answers

Sort by: Most helpful
  1. CarrinWu-MSFT 6,866 Reputation points
    2021-06-22T08:09:04.003+00:00

    Hi @Joel ,

    Welcome to Microsoft Q&A!

    Please refer to Python tutorials for SQL machine learning, I think the tutorials could help you to run python script into SQL Server.
    108048-python.png

    Best regards,
    Carrin


    If the answer is helpful, please click "Accept Answer" and upvote it.
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


  2. Niels Berglund 11 Reputation points MVP
    2021-06-30T17:39:37.643+00:00

    Hi there @Joel !

    OK, as I wrote above, I did some further investigations - and I made it to work. However to get it to work I used an open source Python version in SQL Server. In SQL Server 2019 CU3+ you have the ability to install your own Python, (and R), runtime, and not use the "standard" Microsoft runtime. For more of that see my post here: https://nielsberglund.com/2020/12/29/updated-bring-your-own-r--python-runtimes-to-sql-server-extensibility-framework/.

    Anyway, what you do is you import your .pyd file as you would with any import and the use it. An example below:

    EXEC sp_execute_external_script   
    @language =N'p39',  
    @script=   
    N'  
    import sys   
    import os  
    sys.path.append(os.path.abspath("W:/pythontest"))  
     from hello import hello42  
      
    hello42()'  
    

    In the snippet above I have:

    • created my own Python language, which I call p39 (as per my blog posts)
    • I have a .pyd file named hello.pyd, and it is located in w:\pythontest.
    • In that file I have a function called hello42.

    In my Python script I do some imports followed by from ... and then I just use it. The one thing to think about is that you need to assign the permissions to "ALL APPLICATION PACKAGES" to the directory where your .pyd file is as well as the file itself like so:

    icacls w:\pythontest /grant *S-1-15-2-1:(OI)(CI)F /t  
    

    Hope this helps!

    Niels