Giter VIP home page Giter VIP logo

xray-core-python's Introduction

Xray-core-python

Deploy PyPI

Python bindings for Xray-core.

Install

Core Building Tools

You have to install the following tools to be able to install this package successfully.

  • go in your PATH. go 1.20.0 and above is recommended. To check go is ready, type go version. Also, if google service is blocked in your region(such as Mainland China), you have to configure your GOPROXY to be able to pull go packages. For Chinese users, refer to goproxy.cn for more information.

  • cmake in your PATH. To check cmake is ready, type cmake --version.

  • A working GNU C++ compiler(i.e. GNU C++ toolchains). To check GNU C++ compiler is ready, type g++ --version. These tools should have been installed in Linux or macOS by default. If you don't have GNU C++ toolchains(especially for Windows users) anyway:

    • For Linux users: type sudo apt update && sudo apt install g++ and that should work out fine.
    • For Windows users: install MinGW-w64 or Cygwin and make sure you have add them to PATH.

Install Package

pip install Xray-core

API

>>> import xray
>>> help(xray) 
Help on package xray:                                                                                                                                                                                       

NAME
    xray

PACKAGE CONTENTS
    xray

FUNCTIONS
    queryStats(...) method of builtins.PyCapsule instance
        queryStats(apiServer: str, timeout: int, myPattern: str, reset: bool) -> str

        Query statistics from Xray

    startFromJSON(...) method of builtins.PyCapsule instance
        startFromJSON(json: str) -> None

        Start Xray client with JSON string

Source Code Modification

This repository, including the package that distributes to pypi, contains Xray-core source code that's been modified to build the binding and specific API. If without explicitly remark, the version of this package corresponds to the version of the origin source code tag, so the binding will have full features as the original go distribution will have. And due to its backward compatibility, there's no plan to generate bindings for older release of Xray-core.

To make installation of this package easier, I didn't add the original Xray-core source code as a submodule. To track what modifications have been made to the source code, you can compare it with the same version under Python binding and corresponding go repository.

Tested Platform

Xray-core-python works on all major platform with all Python version(Python 3).

Below are tested build in github actions.

Platform Python 3.7-Python 3.11
ubuntu 20.04 ✔️
ubuntu 22.04 ✔️
windows-2019 ✔️
windows-2022 ✔️
macos-11 ✔️
macos-12 ✔️
macos-13 ✔️

License

The license for this project follows its original go repository Xray-core and is under MPL 2.0.

xray-core-python's People

Contributors

loreneteval avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

xray-core-python's Issues

How to start xray from go program?

Hi @LorenEteval
I know that creating an issue to ask questions is not right. But can you give me some advices?
I want to create a new_main.go file to start a xray from my config file.
This is my source code locate at Xray-core-python/xray-go:

import (
	"fmt"
	"os"
	"github.com/xtls/xray-core/core"
)

func startXrayFromJSON(jsonString string) (core.Server, error) {
	c, err := core.ConfigBuilderForJson(jsonString)
	if err != nil {
		fmt.Println(err)
	}

	server, err := core.New(c)
	if err != nil {
		return nil, err
	}

	return server, nil
}

func main() {
	jsonString := `
	{
	"inbounds": [{
		"port": 1080,
		"protocol": "socks",
		"settings": {
			"auth": "noauth",
			"udp": true
		},
		"tag": "inbounds"
	}],
	"outbounds": [{
		"protocol": "freedom",
		"settings": {},
		"tag": "outbound"
	}, {
		"protocol": "blackhole",
		"settings": {},
		"tag": "blocked"
	}],
	"routing": {
		"domainStrategy": "IPOnDemand",
		"rules": [{
			"type": "field",
			"inboundTag": "inbound",
			"outboundTag": "blocked"
		}]
	}
	}
	`
	server_xray, _ := startXrayFromJSON(jsonString)
	if server_xray == nil {
		fmt.Println("nil server")
	}
	if err := server_xray.Start(); err != nil {
		fmt.Println("Failed to start:", err)
		os.Exit(-1)
	}
	defer server_xray.Close()
}

I got the error that:

go run server.go
panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x0 pc=0x60861e]

goroutine 1 [running]:
main.startXrayFromJSON({0x6923bf?, 0xc000028000?})
        /opt/Xray-core-python/xray-go/server.go:10 +0x1e
main.main()
        /opt/Xray-core-python/xray-go/server.go:54 +0x3a
exit status 2

Hi,I want change the module name ,how should I do?

Hi ,
I downloaded your source to build the xray.pyd by myself. but I don`t want the file named xray. I simplely change the file name to e.g gobee.pyd and import it to my code like this:

import gobee
gobee.StartFromJson

I doesn`t work. so how could I change the building params to achive this purpose? thank you for your kindly response

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.