Giter Site home page Giter Site logo

pythonkit's Introduction

PythonKit

Swift framework to interact with Python.

Requirements

PythonKit requires Swift 5 or higher and has been tested on macOS, Linux and Windows.

Usage

Some Python code like this:

import sys

print(f"Python {sys.version_info.major}.{sys.version_info.minor}")
print(f"Python Version: {sys.version}")
print(f"Python Encoding: {sys.getdefaultencoding().upper()}")

Can be implemented in Swift through PythonKit with the following code:

import PythonKit

let sys = try Python.import("sys")

print("Python \(sys.version_info.major).\(sys.version_info.minor)")
print("Python Version: \(sys.version)")
print("Python Encoding: \(sys.getdefaultencoding().upper())")

Swift Package Manager

Add the following dependency to your Package.swift manifest:

.package(url: "https://github.com/pvieito/PythonKit.git", .branch("master")),

Build

PythonKit can be built with Swift PM:

$ cd PythonKit
$ swift run
[*] Python 3.7
[ ] Version: 3.7.0

The Python library will be loaded at runtime, PythonKit 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.

$ PYTHON_VERSION=3 swift run
[*] Python 3.5
[ ] Version: 3.5.2
$ PYTHON_VERSION=2.7 swift run
[*] Python 2.7
[ ] Version: 2.7.10
$ PYTHON_LIBRARY=libpython3.5.so swift run
[*] Python 3.5
[ ] Version: 3.5.2
$ PYTHON_LIBRARY=/usr/lib/x86_64-linux-gnu/libpython2.7.so swift run
[*] Python 2.7
[ ] Version: 2.7.10

Notes

PythonKit is based on the Python module from the Swift for TensorFlow project. Currently both modules are equivalent, the mantainers have been developing them jointly and are kept in sync.

pythonkit's People

Contributors

pvieito avatar turbolent avatar dan-zheng avatar compnerd avatar

Watchers

James Cloos avatar Ilya Mikhaltsou avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.