{"id":13461786,"url":"https://github.com/pvieito/PythonKit","last_synced_at":"2025-03-24T22:35:02.523Z","repository":{"id":40650327,"uuid":"121997410","full_name":"pvieito/PythonKit","owner":"pvieito","description":"Swift framework to interact with Python.","archived":false,"fork":false,"pushed_at":"2024-09-06T00:09:03.000Z","size":280,"stargazers_count":1964,"open_issues_count":0,"forks_count":220,"subscribers_count":38,"default_branch":"master","last_synced_at":"2025-03-05T17:02:35.060Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Swift","has_issues":false,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/pvieito.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2018-02-18T22:39:44.000Z","updated_at":"2025-03-04T21:26:08.000Z","dependencies_parsed_at":"2023-11-08T04:47:24.366Z","dependency_job_id":"1bae9d4c-aa9c-492d-a7d4-16334ac01518","html_url":"https://github.com/pvieito/PythonKit","commit_stats":{"total_commits":281,"total_committers":15,"mean_commits":"18.733333333333334","dds":0.2099644128113879,"last_synced_commit":"060e1c8b0d14e4d241b3623fdbe83d0e3c81a993"},"previous_names":[],"tags_count":12,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pvieito%2FPythonKit","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pvieito%2FPythonKit/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pvieito%2FPythonKit/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pvieito%2FPythonKit/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/pvieito","download_url":"https://codeload.github.com/pvieito/PythonKit/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245366204,"owners_count":20603438,"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":[],"created_at":"2024-07-31T11:00:57.564Z","updated_at":"2025-03-24T22:34:57.493Z","avatar_url":"https://github.com/pvieito.png","language":"Swift","readme":"\n#  PythonKit\n[![](https://img.shields.io/endpoint?url=https%3A%2F%2Fswiftpackageindex.com%2Fapi%2Fpackages%2Fpvieito%2FPythonKit%2Fbadge%3Ftype%3Dswift-versions)](https://swiftpackageindex.com/pvieito/PythonKit)\n[![](https://img.shields.io/endpoint?url=https%3A%2F%2Fswiftpackageindex.com%2Fapi%2Fpackages%2Fpvieito%2FPythonKit%2Fbadge%3Ftype%3Dplatforms)](https://swiftpackageindex.com/pvieito/PythonKit)\n\nSwift framework to interact with Python.\n\n## Usage\n\nSome Python code like this:\n\n```python\nimport sys\n\nprint(f\"Python {sys.version_info.major}.{sys.version_info.minor}\")\nprint(f\"Python Version: {sys.version}\")\nprint(f\"Python Encoding: {sys.getdefaultencoding().upper()}\")\n```\n\nCan be implemented in Swift through PythonKit with the following code:\n\n```swift\nimport PythonKit\n\nlet sys = Python.import(\"sys\")\n\nprint(\"Python \\(sys.version_info.major).\\(sys.version_info.minor)\")\nprint(\"Python Version: \\(sys.version)\")\nprint(\"Python Encoding: \\(sys.getdefaultencoding().upper())\")\n```\n\n### Swift Package Manager\n\nAdd the following dependency to your `Package.swift` manifest:\n\n```swift\n.package(url: \"https://github.com/pvieito/PythonKit.git\", branch: \"master\"),\n```\n\n## Environment Variables\n\nAs the Python library are loaded at runtime by **PythonKit**, it will try to find the most modern Python version available in the system. You can force a given version with the `PYTHON_VERSION` environment variable or an specific Python library path or name with `PYTHON_LIBRARY`.\n\n```\n$ PYTHON_VERSION=3 swift run\n[*] Python 3.5\n$ PYTHON_VERSION=2.7 swift run\n[*] Python 2.7\n$ PYTHON_LIBRARY=libpython3.5.so swift run\n[*] Python 3.5\n$ PYTHON_LIBRARY=/usr/lib/x86_64-linux-gnu/libpython2.7.so swift run\n[*] Python 2.7\n```\n\nIf **PythonKit** cannot find and load the Python library you can set the `PYTHON_LOADER_LOGGING` environment variable to know from which locations **PythonKit** is trying to load the library:\n\n```\n$ PYTHON_LOADER_LOGGING=TRUE PYTHON_VERSION=3.8 swift run\nLoading symbol 'Py_Initialize' from the Python library...\nTrying to load library at 'Python.framework/Versions/3.8/Python'...\nTrying to load library at '/usr/local/Frameworks/Python.framework/Versions/3.8/Python'...\nFatal error: Python library not found. Set the PYTHON_LIBRARY environment variable with the path to a Python library.\n```\n\n## Troubleshooting\n\n- If your are targeting the Mac platform with the [Hardened Runtime](https://developer.apple.com/documentation/security/hardened_runtime) enabled make sure you are properly signing and embedding the Python framework you are trying to load with **PythonKit**. The Hardened Runtime [Library Validation mechanism](https://developer.apple.com/documentation/bundleresources/entitlements/com_apple_security_cs_disable-library-validation) prevents a process from loading libraries that are not signed by Apple or the same developer as the main process.\n\n\n## Notes\n\n- Originally **PythonKit** was based on the `Python` module from the [**Swift for TensorFlow**](https://github.com/tensorflow/swift) experimental project.\n- If you have questions about **PythonKit** you can ask on the [**Swift Forums**](https://forums.swift.org/c/related-projects/).\n","funding_links":[],"categories":["Swift","HarmonyOS","etc"],"sub_categories":["Windows Manager"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpvieito%2FPythonKit","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpvieito%2FPythonKit","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpvieito%2FPythonKit/lists"}