Skip to content

Commit 6daac52

Browse files
author
TaqiNasiri
committed
Add Nuget Settings
1 parent 39f113f commit 6daac52

File tree

3 files changed

+128
-12
lines changed

3 files changed

+128
-12
lines changed

Diff for: Logo.png

5.97 KB
Loading

Diff for: README.md

+97-1
Original file line numberDiff line numberDiff line change
@@ -1 +1,97 @@
1-
# PythonNet.Helper
1+
# PythonNet.Helper
2+
Bring Python to C# !!!
3+
4+
[![Nuget](https://img.shields.io/nuget/v/PythonNet.Helper?logo=nuget&style=for-the-badge&color=00467C&labelColor=1c1917)](https://www.nuget.org/packages/PythonNet.Helper)
5+
6+
>This library is a help library for [PythonNet](https://github.com/pythonnet/pythonnet), if you find any bugs, please report them. Also let me know if you have any comments
7+
8+
## Install via NuGet
9+
To install Atrob, run the following command in the Package Manager Console :
10+
```powershell
11+
PM> Install-Package PythonNet.Helper
12+
```
13+
14+
## Usage
15+
**To use this library, you must have .NET and Python installed**
16+
17+
To start, make an instance of PyNet as below and give the Python DLL path
18+
```csharp
19+
IPyNet pyNet = new PyNet(@"C:\Program Files\Python311\python311.dll");
20+
```
21+
22+
Now you can use `RunPython` which has many overloads whose parameter list and input type are listed below
23+
24+
|Name|Type|Description|
25+
|----|----|-----------|
26+
|pythonCode|`string`|Python code to be executed|
27+
|parameters|`IDictionary<string, object>`|The list of input parameters in the form of a dictionary, which is the key of the variable name in Python|
28+
|returnedVariableNames|`string[]`|The names of the variables that are supposed to be taken from the Python code|
29+
|returnedVariableNames|`string[]`|The names of the variables that are supposed to be taken from the Python code|
30+
|parameter|`(string key, object value)`|To pass a parameter instead of using a dictionary|
31+
|returnedVariableName|`string`|To get just one return value instead of using an array|
32+
33+
## Samples
34+
35+
36+
37+
### Run
38+
```csharp
39+
pyNet.RunPython("print('Welcome To PythonNet.Helper')");
40+
```
41+
42+
### Run From File
43+
You can give the address of the code file and use `ReadFile` to read the code as below
44+
```csharp
45+
pyNet.RunPython("PythonFiles/HelloWorld.py".ReadFile());
46+
```
47+
48+
### By Parameters
49+
- Parameter
50+
```csharp
51+
pyNet.RunPython(@$"print('Hello ' + name)", ("name", "Mohammad Taqi"));
52+
```
53+
54+
- Parameters
55+
```csharp
56+
pyNet.RunPython("print(fname + ' ' + lname)", new Dictionary<string, object>
57+
{
58+
["fname"] = "Mohammad Taqi",
59+
["lname"] = "Nasiri"
60+
});
61+
```
62+
63+
- Model parameter
64+
65+
```csharp
66+
public class UserModel
67+
{
68+
public string Name { get; set; } = string.Empty;
69+
public string Family { get; set; } = string.Empty;
70+
public DateTime BirthDay { get; set; }
71+
}
72+
```
73+
74+
```csharp
75+
pyNet.RunPython("print(f'Name : {user.Name} | Family : {user.Family} | BirthDay : {user.BirthDay}')",("user",new UserModel()
76+
{
77+
Name = "Mohammad Taqi",
78+
Family = "Nasiri",
79+
BirthDay = DateTime.Now
80+
}));
81+
```
82+
83+
### By returned Variables
84+
85+
- Without parameter
86+
87+
```csharp
88+
pyNet.RunPython("from datetime import date\n" + "today = date.today()", "today")
89+
```
90+
91+
92+
- By parameter
93+
```csharp
94+
int sumNumbers = Convert.ToInt32(pyNet.RunPython("sum = sum(nums)", ("nums", new List<int>() { 1, 5, 8, 7, 15, 20, 36 }), "sum").ToString())
95+
```
96+
97+
>You can also pass multiple parameters with a dictionary

Diff for: src/PythonNet.Helper/PythonNet.Helper.csproj

+31-11
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,36 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22

3-
<PropertyGroup>
4-
<TargetFramework>net7.0</TargetFramework>
5-
<ImplicitUsings>enable</ImplicitUsings>
6-
<Nullable>enable</Nullable>
7-
<Title>PythonNet.Helper</Title>
8-
<Version>1.0.0</Version>
9-
<Authors>Mohammad Taqi Nasiri</Authors>
10-
</PropertyGroup>
3+
<PropertyGroup>
4+
<TargetFramework>net7.0</TargetFramework>
5+
<ImplicitUsings>enable</ImplicitUsings>
6+
<Nullable>enable</Nullable>
7+
<Title>PythonNet.Helper</Title>
8+
<Version>1.0.0</Version>
9+
<Authors>Mohammad Taqi Nasiri</Authors>
10+
<Description>
11+
Bring Python to C#
12+
</Description>
13+
<PackageProjectUrl>https://github.com/taqinasiri/PythonNet.Helper</PackageProjectUrl>
14+
<PackageIcon>Logo.png</PackageIcon>
15+
<RepositoryUrl>https://github.com/taqinasiri/PythonNet.Helper</RepositoryUrl>
16+
<PackageTags>.NETCore;.Net;Python;PythonNet</PackageTags>
17+
<GeneratePackageOnBuild>True</GeneratePackageOnBuild>
18+
<PackageReadmeFile>README.md</PackageReadmeFile>
19+
</PropertyGroup>
1120

12-
<ItemGroup>
13-
<PackageReference Include="pythonnet" Version="3.0.1" />
14-
</ItemGroup>
21+
<ItemGroup>
22+
<None Include="..\..\Logo.png">
23+
<Pack>True</Pack>
24+
<PackagePath>\</PackagePath>
25+
</None>
26+
<None Include="..\..\README.md">
27+
<Pack>True</Pack>
28+
<PackagePath>\</PackagePath>
29+
</None>
30+
</ItemGroup>
31+
32+
<ItemGroup>
33+
<PackageReference Include="pythonnet" Version="3.0.1" />
34+
</ItemGroup>
1535

1636
</Project>

0 commit comments

Comments
 (0)