All Projects → adamdriscoll → Snek

adamdriscoll / Snek

Licence: mit
PowerShell wrapper around Python for .NET to invoke Python from PowerShell

Programming Languages

python
139335 projects - #7 most used programming language
powershell
5483 projects

Projects that are alternatives of or similar to Snek

Nothing Private
Do you think you are safe using private browsing or incognito mode?. 😄 👿 This will prove that you're wrong.
Stars: ✭ 1,375 (+1234.95%)
Mutual labels:  hacktoberfest
Circe Yaml
YAML parser for circe using SnakeYAML
Stars: ✭ 102 (-0.97%)
Mutual labels:  hacktoberfest
Atoum
The modern, simple and intuitive PHP unit testing framework.
Stars: ✭ 1,382 (+1241.75%)
Mutual labels:  hacktoberfest
React Ladies
We're a group of women and non-binary ReactJS enthusiasts in New York City (and beyond).
Stars: ✭ 102 (-0.97%)
Mutual labels:  hacktoberfest
Swagger Combine
Combines multiple Swagger schemas into one dereferenced schema.
Stars: ✭ 102 (-0.97%)
Mutual labels:  hacktoberfest
Generators
Laravel File Generators with config and publishable stubs
Stars: ✭ 102 (-0.97%)
Mutual labels:  hacktoberfest
Os Autoinst
OS-level test automation
Stars: ✭ 99 (-3.88%)
Mutual labels:  hacktoberfest
Boots
The DHCP and iPXE server for Tinkerbell.
Stars: ✭ 101 (-1.94%)
Mutual labels:  hacktoberfest
Ex gram
Telegram Bot API low level API and framework
Stars: ✭ 103 (+0%)
Mutual labels:  hacktoberfest
Openvpn
Development repository for the openvpn cookbook
Stars: ✭ 102 (-0.97%)
Mutual labels:  hacktoberfest
Lychee
The most complete and powerful data-binding library and persistence infra for Kotlin 1.3, Android & Splitties Views DSL, JavaFX & TornadoFX, JSON, JDBC & SQLite, SharedPreferences.
Stars: ✭ 102 (-0.97%)
Mutual labels:  hacktoberfest
Tabfern
Google Chrome extension for saving and restoring sets of tabs, and for switching between windows and tabs from a vertical, grouped list.
Stars: ✭ 102 (-0.97%)
Mutual labels:  hacktoberfest
Uiviewcontroller Keyboardadditions
Tiny UIViewController category that provides handy way for keyboard handling logic.
Stars: ✭ 102 (-0.97%)
Mutual labels:  hacktoberfest
River pod
A simple way to access state while robust and testable.
Stars: ✭ 1,366 (+1226.21%)
Mutual labels:  hacktoberfest
S4
Simple Shamir's Secret Sharing (s4) - A go package giving a easy to use interface for the shamir's secret sharing algorithm
Stars: ✭ 103 (+0%)
Mutual labels:  hacktoberfest
Insideheartz Whatsapp Bot
A multipurpose whatsapp bot buillt on node.js
Stars: ✭ 102 (-0.97%)
Mutual labels:  hacktoberfest
Php Composter
Git Hooks Management through Composer
Stars: ✭ 102 (-0.97%)
Mutual labels:  hacktoberfest
Cuban Opensource
Awesome list of Cuban opensource projects. Just to know what is being openly developed in Cuba.
Stars: ✭ 103 (+0%)
Mutual labels:  hacktoberfest
Covid19 Review
A collaborative review of the emerging COVID-19 literature. Join the chat here:
Stars: ✭ 102 (-0.97%)
Mutual labels:  hacktoberfest
Gate
Spinnaker API Gateway
Stars: ✭ 102 (-0.97%)
Mutual labels:  hacktoberfest

Snek

PowerShell wrapper around Python for .NET to invoke Python from PowerShell

Install snek

Install-Module snek

Requirements

  • Python v2.7, v3.5, v3.6, or v3.7 (defaults to python 3.7)

Functions

  • Use-Python
  • Invoke-Python
  • Import-PythonRuntime
  • Import-PythonPackage
  • Install-PythonPackage
  • Uninstall-PythonPackage
  • Use-PythonScope
  • Set-PythonVariable

Invoke Python Code (v3.7)

Use-Python { 
    Invoke-Python -Code "print('hi!')" 
}
    
hi!

Invoke Python Code (v2.7)

PS > Use-Python { 
    Invoke-Python -Code "print('hi!')" 
} -Version v2.7
    
hi!

Returning A Value from Python to PowerShell

Due to the use of dynamic the type must be cast to the expected type so you need to specify the -ReturnType parameter to do so.

Use-Python {
    Invoke-Python "'Hello'" -ReturnType ([String])
}

Imports the numpy Python module and does some math

Access methods of modules directly!

Use-Python {
    $np = Import-PythonPackage "numpy"
    [float]$np.cos($np.pi * 2)

    [float]$np.sin(5)
    [float]($np.cos(5) + $np.sin(5))
} -Version v3.7

Output

1
-0.9589243
-0.6752621

Manage pip

Format is Install-PythonPackage <package>

Install-PythonPackage requests

Or similarly:

Uninstall-PythonPackage requests

Using Scopes

You can use Python scopes to string together multiple Invoke-Python calls or to pass in variables from PowerShell.

Use-Python {
    Use-PythonScope {
        Invoke-Python -Code "import sys" 
        Invoke-Python -Code "sys.version" -ReturnType ([string]) 
    }
}

Passing a .NET Object to Python

class Person {
    [string]$FirstName
    [string]$LastName
}

Use-Python {
    Use-PythonScope {
        $Person = [Person]::new()
        $Person.FirstName = "Adam"
        $Person.LastName = "Driscoll"
        Set-PythonVariable -Name "person" -Value $Person

        Invoke-Python -Code "person.FirstName + ' ' + person.LastName" -ReturnType ([string])
    }
}
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].