The package registry is still being built. The docs are live, everything else is a preview.

Edge Python

Sign In

Sign in to publish packages and pin them by sha256.


By continuing, you accept our Terms and Conditions.

@
Palette

Built-in functions

Edge Python provides 68 built-in functions. They are first-class values, so you can pass them as arguments, store them in containers, and alias them.

cmd + enter
[3, '-0x3', '-3']
aliased
Output

There is no eval, exec, compile, open, or __import__. Static imports and the sandbox rule them out.

Output

print

print(*args, sep=' ', end='\n') writes the arguments joined by sep, then end. * unpacking spreads an iterable into the arguments. The file and flush keywords are accepted and ignored.

cmd + enter
1 2 3
a-b-c
no newline!
1, 2, 3
Output

input

input() pops one line from the host-provided input buffer and returns it as a string. There is no prompt argument. The CLI fills the buffer from piped stdin, one line per call. An empty buffer raises RuntimeError. In WASM the host copies stdin bytes into the guest input buffer before running.

Numeric

abs

abs(x) returns the absolute value of an int or float. Other types raise TypeError.

cmd + enter
7
3.14
Output

round

round(x) rounds to the nearest integer and returns an int. Ties go to even. round(x, n) rounds to n decimal digits and returns a float. A negative n rounds to tens, hundreds, and so on.

cmd + enter
2
0
-2
1.6
1200
Output

min, max

min(a, b, ...) takes several values or a single iterable. max works the same way. An empty iterable raises ValueError unless a default= is given. A key= function selects the comparison value while the original element is returned.

cmd + enter
1
4
-1
bb
Output

sum

sum(iterable) or sum(iterable, start). An empty iterable sums to start, which defaults to 0.

cmd + enter
6
106
30
Output

pow

pow(base, exp) matches the ** operator. pow(base, exp, mod) does modular exponentiation on integers. The three-argument form requires a non-negative exponent and a modulus with absolute value at most 2^63. A zero modulus raises ZeroDivisionError. The other violations raise ValueError.

cmd + enter
1024
24
7
Output

divmod

divmod(a, b) returns (a // b, a % b) as a tuple. Ints and floats both work. Float operands give a float quotient and remainder.

cmd + enter
(2, 1)
(-3, 2)
(3.0, 1.5)
Output

bin, oct, hex

bin(x), oct(x), and hex(x) format an integer in base 2, 8, or 16 with the matching prefix.

cmd + enter
0b1010
0o10
0xff
-0x100
Output

Type conversion

int

int(x) accepts an int, bool, float, or numeric string. Floats truncate toward zero. Strings accept _ as a digit separator. int(s, base) parses a string in radix 2 to 36, or radix 0 to auto-detect a 0x, 0o, or 0b prefix. Bad strings raise ValueError. int(inf) raises OverflowError and int(nan) raises ValueError. Results are bounded by the integer width.

cmd + enter
3
42
1
255
31
1000
Output

float

float(x) accepts an int, bool, float, or string. Strings recognize inf, -inf, and nan, case-insensitively.

cmd + enter
2.0
3.14
inf
Output

str

str(x) returns the display form of x. No argument gives an empty string. str(bytes, encoding) decodes bytes like bytes.decode.

cmd + enter
42
[1, 2, 3]
None
hi
Output

bool

bool(x) returns the truth value of x. The rules live in Truthy and falsy.

cmd + enter
False True
False True
False True
Output

list, tuple, set, frozenset

Each accepts any iterable and builds a new container. Iterating a dict yields its keys. With no argument, each builds an empty container. A live generator object (a def with yield) is only accepted by list(). The others raise TypeError.

cmd + enter
['a', 'b', 'c']
(0, 1, 2)
{'b', 'a'}
frozenset({1, 2, 3})
Output

dict

dict() builds from a mapping, an iterable of key/value pairs, keyword arguments, or a mix. Each pair must have length 2.

cmd + enter
{'a': 1, 'b': 2}
{'a': 1}
{'a': 1, 'b': 2}
Output

chr, ord

chr(i) returns the one-character string for code point i, across full Unicode. Out-of-range values raise ValueError. ord(c) is the inverse and accepts a length-1 string or length-1 bytes.

cmd + enter
A
65
65
😀
Output

Sequences and iteration

len

len(x) returns the element count of a string (in code points), bytes, list, tuple, dict, set, frozenset, or range. Other types raise TypeError.

cmd + enter
5
4
2
100
Output

range

range(stop), range(start, stop), or range(start, stop, step). Lazy. A zero step raises ValueError and non-integer arguments raise TypeError. Two ranges compare equal when they produce the same sequence of values.

cmd + enter
[0, 1, 2, 3, 4]
[2, 3, 4, 5, 6, 7]
[10, 8, 6, 4, 2]
True
Output

sorted

sorted(iterable) returns a new sorted list. key=fn compares by fn(item). reverse=True flips the order. Numbers, strings, bytes, and lists or tuples order lexicographically. Objects with __lt__ sort by it. Mixing unordered types raises TypeError.

cmd + enter
[1, 1, 3, 4, 5]
['e', 'h', 'l', 'l', 'o']
[5, 4, 3, 1, 1]
['kiwi', 'apple', 'banana']
Output

reversed

reversed(x) returns a new list in reverse order. It is eager, not a lazy iterator. A string becomes a list of one-character strings.

cmd + enter
[3, 2, 1]
['c', 'b', 'a']
Output

enumerate

enumerate(iterable) returns a list of (index, value) tuples. A second argument, positional or start=, sets the first index.

cmd + enter
0 a
1 b
2 c
[(7, 'a'), (8, 'b')]
Output

zip

zip(a, b, ...) returns a list of tuples pairing the inputs, truncated to the shortest. There is no strict= mode.

cmd + enter
1 x
2 y
[(1, 3, 5), (2, 4, 6)]
Output

iter, next

iter(x) returns a fresh iterator over any iterable. It materialises a snapshot, so the original is never mutated. next(it) returns the next item and raises StopIteration when exhausted. next(it, default) returns default instead of raising. The two-argument iter(callable, sentinel) calls callable() until it returns sentinel.

cmd + enter
10
20
30
done
Output

map, filter

map(fn, *iterables) returns a list of fn(items...). Several iterables are walked in parallel and stop at the shortest. filter(pred, iterable) returns a list of items where pred(item) is truthy. A None predicate keeps truthy items. Both are eager.

cmd + enter
[2, 4, 6]
[11, 22]
[3, 4]
[1, 'hi', [1]]
Output

all, any

all(x) and any(x) test truthiness across an iterable and short-circuit at the deciding element. all([]) is True and any([]) is False.

cmd + enter
True
False
True
True
False
Output

slice

slice(stop), slice(start, stop), or slice(start, stop, step) builds a reusable slice object usable as a sequence index.

cmd + enter
[20, 30, 40]
[10, 30, 50]
Output

Bytes helpers

bytes_fromhex(s) parses a hex string into bytes. ASCII whitespace is ignored and non-hex input raises ValueError.

int_from_bytes(b, order) reads bytes as an unsigned integer. order is "big" or "little". At most 8 bytes, anything longer raises OverflowError.

int_to_bytes(n, length, order) converts a non-negative int to length bytes. length is at most 8. A negative n raises ValueError and a value that does not fit raises OverflowError.

The methods bytes.fromhex, int.from_bytes, and int.to_bytes do the same jobs with default arguments and no 8-byte cap.

cmd + enter
b'Hello'
256
b'\x00\xff'
Output

Type and identity

type

type(x) returns the type object of x. The built-in type names are these same objects, so type(x) is int holds, and calling one constructs a value. For a user instance the result is its class object.

cmd + enter
<class 'int'>
True
[4, 5]
True
Output

Functions, type objects, and classes expose __name__, the bare declared name. On an exception instance, type(e).__name__ gives the exception’s class name.

cmd + enter
greet
int
ZeroDivisionError
Output

object

object() returns a unique featureless instance. Use it as a sentinel. Every value is an instance of object.

cmd + enter
False
True
True
Output

isinstance

isinstance(obj, t) tests membership. t is a built-in type, exception class, user class, or a tuple of those. bool counts as int. Exception classes follow the standard hierarchy. User classes walk their inheritance chain. object matches every value.

cmd + enter
True
True
True
Output

issubclass

issubclass(C, B) tests inheritance. B may be a tuple of classes. C must itself be a class or the call raises TypeError. bool is a subclass of int, and exception classes follow the standard hierarchy.

cmd + enter
True
True
True
False
Output

callable

callable(x) is True for functions, lambdas, bound methods, type objects, built-in functions, and instances whose class defines __call__. False for everything else.

cmd + enter
True
True
False
Output

id, hash

id(x) returns a stable numeric identifier for the value. hash(x) returns the hash of a hashable value. Lists, dicts, and sets are unhashable and raise TypeError. Ints hash to themselves. Integral floats hash as the equal int, so hash(1) == hash(1.0).

cmd + enter
True
True
True
unhashable
Output

Representation

repr

repr(x) returns the developer-readable form. Strings are quoted and containers show the repr of their elements.

cmd + enter
'hello'
42
[1, 'two', 3]
Output

format

format(value) returns the display form. format(value, spec) applies the format spec mini-language from f-strings.

cmd + enter
42
00042
3.14
0xff
Output

Attributes

getattr(obj, name) reads an attribute, looking in the instance __dict__, then the class chain, then the built-in method table. A missing name raises AttributeError unless a third argument gives a default.

hasattr(obj, name) runs the same lookup and returns a boolean.

setattr(obj, name, value) writes an attribute on a user instance, class, or function. Built-in types have no writable attributes.

delattr(obj, name) removes an attribute. A missing name raises AttributeError on an instance and is silently ignored on a class.

cmd + enter
42
default
False
Output

vars

vars(x) returns a snapshot of the attribute dict of an instance or module. There is no no-argument form. Use locals() instead.

cmd + enter
{'x': 1, 'y': 2}
Output

globals, locals

globals() returns a fresh dict of the module-level bindings. User names only, since built-ins live in a separate namespace. locals() returns a fresh dict of the current frame’s locals inside a function, and matches globals() at module level. Both are copies. Mutating them does not change bindings.

cmd + enter
100
7
{'b': 2, 'a': 1}
Output

Modules

import_module

import_module(name) returns a module that was imported statically somewhere in the program. It is a lookup, not a load. Every reachable module is still resolved and verified at compile time. An unknown name raises NameError. A name bound to a non-module global, such as a function, raises TypeError.

cmd + enter
True
3
Output

Dynamic loading through importlib or __import__ does not exist. Static imports plus import_module replace it.

Classes

super

super() takes no arguments and must be called inside a method. It returns a proxy that resolves attributes against the bases of the current class, starting one step up. See Inheritance and super().

cmd + enter
ab
Output

property

property(fget, fset=None) builds a descriptor for a class member. Usually applied through @property with an optional @<name>.setter. See Properties.

cmd + enter
9
Output

staticmethod, classmethod

staticmethod(func) wraps a class member so it receives no implicit self. classmethod(func) wraps one so it receives the class as its first argument. Usually applied as decorators. See Static methods and Class methods.

cmd + enter
5
9
Math
Output

Async

These functions drive coroutines. Async owns the full model.

  • run(*coros) runs every argument to completion and returns the first argument’s result. Errors from the other coroutines are discarded.
  • gather(*coros) runs every argument and returns a list of results in argument order. The first error propagates.
  • sleep(seconds) suspends for the duration. A negative value clamps to zero.
  • with_timeout(seconds, coro) returns the coroutine’s result or raises TimeoutError at the deadline.
  • cancel(coro) flags a coroutine for cancellation at its next step.
  • frame() suspends until the host’s next render frame.
  • receive() pops the oldest queued host message.
cmd + enter
[2, 4, 6]
42
Output