{"id":13590947,"url":"https://github.com/pythonnet/pythonnet","last_synced_at":"2025-05-13T15:09:08.055Z","repository":{"id":12154241,"uuid":"14748123","full_name":"pythonnet/pythonnet","owner":"pythonnet","description":"Python for .NET is a package that gives Python programmers nearly seamless integration with the .NET Common Language Runtime (CLR) and provides a powerful application scripting tool for .NET developers.","archived":false,"fork":false,"pushed_at":"2025-04-27T15:29:37.000Z","size":9888,"stargazers_count":5043,"open_issues_count":151,"forks_count":746,"subscribers_count":153,"default_branch":"master","last_synced_at":"2025-05-05T18:25:42.373Z","etag":null,"topics":["clr","csharp","dotnet","ffi","hacktoberfest","mono","python","pythonnet"],"latest_commit_sha":null,"homepage":"http://pythonnet.github.io","language":"C#","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/pythonnet.png","metadata":{"files":{"readme":"README.rst","changelog":"CHANGELOG.md","contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":"AUTHORS.md","dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2013-11-27T13:42:20.000Z","updated_at":"2025-05-04T21:17:06.000Z","dependencies_parsed_at":"2023-11-08T04:36:55.702Z","dependency_job_id":"4ccff812-096f-444f-a51f-27ebc9b40ba5","html_url":"https://github.com/pythonnet/pythonnet","commit_stats":{"total_commits":1696,"total_committers":110,"mean_commits":"15.418181818181818","dds":0.7464622641509434,"last_synced_commit":"131b466dcaa9cf9135f3b1859c8a41ee229cace8"},"previous_names":[],"tags_count":30,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pythonnet%2Fpythonnet","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pythonnet%2Fpythonnet/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pythonnet%2Fpythonnet/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pythonnet%2Fpythonnet/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/pythonnet","download_url":"https://codeload.github.com/pythonnet/pythonnet/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252552003,"owners_count":21766619,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["clr","csharp","dotnet","ffi","hacktoberfest","mono","python","pythonnet"],"created_at":"2024-08-01T16:00:52.078Z","updated_at":"2025-05-05T18:26:15.265Z","avatar_url":"https://github.com/pythonnet.png","language":"C#","readme":"pythonnet - Python.NET\n===========================\n\n|Join the chat at https://gitter.im/pythonnet/pythonnet| |stackexchange shield|\n\n|gh shield|\n\n|license shield|\n\n|pypi package version| |conda-forge version| |python supported shield|\n\n|nuget preview shield| |nuget release shield|\n\nPython.NET is a package that gives Python programmers nearly\nseamless integration with the .NET Common Language Runtime (CLR) and\nprovides a powerful application scripting tool for .NET developers. It\nallows Python code to interact with the CLR, and may also be used to\nembed Python into a .NET application.\n\nCalling .NET code from Python\n-----------------------------\n\nPython.NET allows CLR namespaces to be treated essentially as Python packages.\n\n.. code-block:: python\n\n   import clr\n   from System import String\n   from System.Collections import *\n\nTo load an assembly, use the ``AddReference`` function in the ``clr``\nmodule:\n\n.. code-block:: python\n\n   import clr\n   clr.AddReference(\"System.Windows.Forms\")\n   from System.Windows.Forms import Form\n\nBy default, Mono will be used on Linux and macOS, .NET Framework on Windows. For\ndetails on the loading of different runtimes, please refer to the documentation.\n\n.NET Core\n~~~~~~~~~\n\nIf .NET Core is installed in a default location or the ``dotnet`` CLI tool is on\nthe ``PATH``, loading it instead of the default (Mono/.NET Framework) runtime\njust requires setting either the environment variable\n``PYTHONNET_RUNTIME=coreclr`` or calling ``pythonnet.load`` explicitly:\n\n.. code-block:: python\n\n   from pythonnet import load\n   load(\"coreclr\")\n\n   import clr\n\n\nEmbedding Python in .NET\n------------------------\n\n-  You must set ``Runtime.PythonDLL`` property or ``PYTHONNET_PYDLL`` environment variable\n   starting with version 3.0, otherwise you will receive ``BadPythonDllException``\n   (internal, derived from ``MissingMethodException``) upon calling ``Initialize``.\n   Typical values are ``python38.dll`` (Windows), ``libpython3.8.dylib`` (Mac),\n   ``libpython3.8.so`` (most other Unix-like operating systems).\n-  Then call ``PythonEngine.Initialize()``. If you plan to use Python objects from\n   multiple threads, also call ``PythonEngine.BeginAllowThreads()``.\n-  All calls to python should be inside a\n   ``using (Py.GIL()) {/* Your code here */}`` block.\n-  Import python modules using ``dynamic mod = Py.Import(\"mod\")``, then\n   you can call functions as normal, eg ``mod.func(args)``.\n-  Use ``mod.func(args, Py.kw(\"keywordargname\", keywordargvalue))`` or\n   ``mod.func(args, keywordargname: keywordargvalue)`` to apply keyword\n   arguments.\n-  All python objects should be declared as ``dynamic`` type.\n-  Mathematical operations involving python and literal/managed types\n   must have the python object first, eg. ``np.pi * 2`` works,\n   ``2 * np.pi`` doesn't.\n\nExample\n~~~~~~~\n\n.. code-block:: csharp\n\n   static void Main(string[] args)\n   {\n       PythonEngine.Initialize();\n       using (Py.GIL())\n       {\n           dynamic np = Py.Import(\"numpy\");\n           Console.WriteLine(np.cos(np.pi * 2));\n\n           dynamic sin = np.sin;\n           Console.WriteLine(sin(5));\n\n           double c = (double)(np.cos(5) + sin(5));\n           Console.WriteLine(c);\n\n           dynamic a = np.array(new List\u003cfloat\u003e { 1, 2, 3 });\n           Console.WriteLine(a.dtype);\n\n           dynamic b = np.array(new List\u003cfloat\u003e { 6, 5, 4 }, dtype: np.int32);\n           Console.WriteLine(b.dtype);\n\n           Console.WriteLine(a * b);\n           Console.ReadKey();\n       }\n   }\n\nOutput:\n\n.. code:: csharp\n\n   1.0\n   -0.958924274663\n   -0.6752620892\n   float64\n   int32\n   [  6.  10.  12.]\n\n\n\nResources\n---------\n\nInformation on installation, FAQ, troubleshooting, debugging, and\nprojects using pythonnet can be found in the Wiki:\n\nhttps://github.com/pythonnet/pythonnet/wiki\n\nMailing list\n    https://mail.python.org/mailman/listinfo/pythondotnet\nChat\n    https://gitter.im/pythonnet/pythonnet\n\n.NET Foundation\n---------------\nThis project is supported by the `.NET Foundation \u003chttps://dotnetfoundation.org\u003e`_.\n\n.. |Join the chat at https://gitter.im/pythonnet/pythonnet| image:: https://badges.gitter.im/pythonnet/pythonnet.svg\n   :target: https://gitter.im/pythonnet/pythonnet?utm_source=badge\u0026utm_medium=badge\u0026utm_campaign=pr-badge\u0026utm_content=badge\n.. |license shield| image:: https://img.shields.io/badge/license-MIT-blue.svg?maxAge=3600\n   :target: ./LICENSE\n.. |pypi package version| image:: https://img.shields.io/pypi/v/pythonnet.svg\n   :target: https://pypi.python.org/pypi/pythonnet\n.. |python supported shield| image:: https://img.shields.io/pypi/pyversions/pythonnet.svg\n   :target: https://pypi.python.org/pypi/pythonnet\n.. |stackexchange shield| image:: https://img.shields.io/badge/StackOverflow-python.net-blue.svg\n   :target: http://stackoverflow.com/questions/tagged/python.net\n.. |conda-forge version| image:: https://img.shields.io/conda/vn/conda-forge/pythonnet.svg\n   :target: https://anaconda.org/conda-forge/pythonnet\n.. |nuget preview shield| image:: https://img.shields.io/nuget/vpre/pythonnet\n   :target: https://www.nuget.org/packages/pythonnet/\n.. |nuget release shield| image:: https://img.shields.io/nuget/v/pythonnet\n   :target: https://www.nuget.org/packages/pythonnet/\n.. |gh shield| image:: https://github.com/pythonnet/pythonnet/workflows/GitHub%20Actions/badge.svg\n   :target: https://github.com/pythonnet/pythonnet/actions?query=branch%3Amaster\n","funding_links":[],"categories":["Microsoft Windows","C# #","Uncategorized","C# Libraries","Interoperability","微软的 Windows 平台","资源列表","C#","Microsoft Windows [🔝](#readme)","互操作","🗒️ Cheatsheets","Awesome Python","Identifiers"],"sub_categories":["Uncategorized","微软的 Windows 平台","GUI - other","📦 Libraries","Microsoft Windows"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpythonnet%2Fpythonnet","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpythonnet%2Fpythonnet","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpythonnet%2Fpythonnet/lists"}