Skip to main content

a simple, easy to understand language with easy integration capabilities.

Project description

Build Status Discord server invite PyPI version info PyPI supported Python versions

Viper

Viper is a simple, easy to understand language with easy integration capabilities.

Install

Viper is available for python 3.6+.
Viper is now on pypi! It can be installed via
python -m pip install viper-lang

The dev version can be installed via

python -m pip install -U git+https://github.com/IAmTomahawkx/viper-lang

And can be imported into your project

import viper

Python Usage

To use Viper in your application, make use of the two eval methods, viper.eval and viper.eval_file functions. These functions are asynchronous, and must be run using asyncio, whether that be through the await keyword, or something such as asyncio.run. The asyncio docs can be found here.

import viper
import asyncio
code = 'myvar = "hi"'
asyncio.run(viper.eval(code))

or

import asyncio
import viper
asyncio.run(viper.eval_file("myfile.vp"))

you can pass defaults to be injected into the namespace, as such

import asyncio
import viper
asyncio.run(viper.eval("say(myvar)", injected={"myvar": "blue"}))

for more control over the creation, you can create your own viper.Runtime instance

import asyncio
import viper

runtime = viper.Runtime("<input>", injected={"myvar": "blue"}, allow_unsafe_imports=False)
code = "say(myvar)"
asyncio.run(runtime.run(code))

You can use this to disable features like unsafe modules, such as the requests module, or the files module.

import asyncio
import viper

runtime = viper.Runtime("<input>", allow_unsafe_imports=False)
code = "import files"
asyncio.run(runtime.run(code))

The above will raise a ViperModuleError.

Syntax

Variables

variables are set like in python, but with a dollar sign ($) in front of the name. variables are retrieved in the same way, the name with a dollar sign ($) in front. variables can be marked as static by putting static in front of the variable name. static variables cannot be changed by anything other than intervention in python code

myvar = "red"

static mystaticvar = "blue"

mystaticvar = "hello"  <-- StaticError

functions

functions are created either in python and passed to the namespace, or in viper. functions created in viper follow this syntax

func myfunc() {
    return
}

quite similar to python, with a few key differences. you may put static ` in front of the `func keyword to mark the function as static, preventing it from being reassigned.

static func myfunc() {
    return
}

arguments look like the following

func myfunc(argument1, argument2) {
    return
}

an argument can be made optional by inserting a question mark (?) in front of the argument name, E.x.

func myfunc(argument1, ?optional_arg1) {
    return
}

optional arguments that are not given will be passed as a none object (note that this is not the same as a python None)

functions are called the same as in python:

func myfunc() {
    return
}
myfunc()

builtins

the viper namespace is left quite empty by default. The following are included in the default namespace: - say(*args) - equivilant to print in python. - help(obj) - prints an objects help. - dir(obj) - lists all attributes an object has.

Types are included in the namespace: - string - integer - bool - dictionary - list

there is also true / false, which are the booleans.

a full example

static globalvar = "hi"

func name(arg, ?arg1) {
    var = 1
    if (var is 1) {
        var += 1
    }
    elif (var is not 1) {
        var = "stuff"
    }
    else {
        var = none
    }
}

func main() {
    say("hi")
    name("hello")
}
main()

Discord.py integration

to make things easier, the viper.exts.discord module makes it easy to pass safe objects, with limited accessibility, to viper, making it easy to pass discord.py models (indirectly) to your users, without fear of leaking your token and/or other sensitive data. Simply pass a discord.py model to its respective exts.discord counterpart, and pass that to your viper namespace

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

viper-lang-1.0.0.tar.gz (25.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

viper_lang-1.0.0-py3-none-any.whl (27.4 kB view details)

Uploaded Python 3

File details

Details for the file viper-lang-1.0.0.tar.gz.

File metadata

  • Download URL: viper-lang-1.0.0.tar.gz
  • Upload date:
  • Size: 25.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/49.2.1 requests-toolbelt/0.9.1 tqdm/4.56.2 CPython/3.9.1

File hashes

Hashes for viper-lang-1.0.0.tar.gz
Algorithm Hash digest
SHA256 b380a37579cc3b90e8530d1942fbf5a3da3f8bf348ac69f4a612b07fc9a6b32c
MD5 3a72540e5e5bc7b825367e7e325999e2
BLAKE2b-256 cd51051011a404823956cad9a7d3f68d0299b369ef304d6bfc48b737d60b1cc9

See more details on using hashes here.

File details

Details for the file viper_lang-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: viper_lang-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 27.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/49.2.1 requests-toolbelt/0.9.1 tqdm/4.56.2 CPython/3.9.1

File hashes

Hashes for viper_lang-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 4a41af31b7b77d708e43a465a10846e564cdc4d147d645eb1e882d6f4b8bc480
MD5 2ccdfc277efc7c09c7d2be9359e58a7a
BLAKE2b-256 a672728f03731e97404b933bd13543c352aa68286af3ab192537fb237a9de6fd

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page