Skip to main content

Espresso ☕

A tiny, type-safe expression parser in python.

This documentation is a WIP

Rationale

In certain cases, there is need for a safe way for the back-end to call functions provided by the client, espresso addresses this through a type-safety post-processing setup to ensure the function always receives the type it was defined with.

Example

import espresso

import random
import string

# An interface between the interpreter frontend and backend
ctx = espresso.Context()

# Namespaces are automatically resolved. In this case, within the space
# random, integer would be defined. Functionally this is syntactic sugar,
# the namespaces are simply nested dictionaries.
ctx.define_function(
    random.randint, ["random", "integer"], ["int", "int"]
)

# Variadic typing is also supported. The method will be passed an array of
# all the arguments (of a singular type).
ctx.define_function(
    random.choice, ["random", "oneOf"], ["*any"]
)
ctx.define_function(
    random.choice, ["random", "oneOfInteger"], ["*int"]
)
ctx.define_function(
    random.choice, ["random", "oneOfString"], ["*str"]
)

def random_string(length=32):
    return "".join(
        random.choice(string.ascii_letters + string.digits) for i in range(length)
    )


# Optional typing, will pass None if not provided
ctx.define_function(
    random_string, ["random", "string"], ["str?"]
)

ctx.eval("random.integer(0, 10)")

Integration and Usage

To see how espresso is integrated into a production SaaS, you can see the YAML Resolver which defines a bunch of functions and handles errors.

- id: random.string(32)
- first_name: person.firstName
- last_name: person.lastName
- age: random.integer(0, 32)
- plan: choices.oneOf("beta", "pro", "free")

Metadata

Release files for python-espresso 1.8.4

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for python-espresso 1.8.4
File Size Uploaded
python-espresso-1.8.4.tar.gz 8.2 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for python-espresso 1.8.4
File Interpreter ABI Platform
python_espresso-1.8.4-py3-none-any.whl Python 3 none any Details

Total release size: 17.9 kB

Release files / python-espresso-1.8.4.tar.gz

Download URL python-espresso-1.8.4.tar.gz
Size 8.2 kB
Tags Source
SHA-256 checksum
How to use checksums
4e56648fa744598d1f342f9cb23606d2376620f4862cf7752564e82994daf641
BLAKE2b-256 checksum
How to use checksums
f70a450af44f210fab7ab4ab880ed5b9254511d1f8580624a1e29837db2f65fb
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.0.0 CPython/3.11.6

Release files / python_espresso-1.8.4-py3-none-any.whl

Download URL python_espresso-1.8.4-py3-none-any.whl
Size 9.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
551a915ddebe7c386a1aa958d9d6e020e62ac71a7ad7858f3ee8fce63f85f6b4
BLAKE2b-256 checksum
How to use checksums
8275ddfbf37203a774fab1c141c4140523ab78d692ef72a045e935a034a00518
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.0.0 CPython/3.11.6

Release history Release notifications | RSS feed

This release

1.8.4 This release

2 release files

1.8.3

2 release files

1.8.2

2 release files

1.8.1

2 release files

1.8.0

2 release files

1.7

2 release files

1.6

2 release files

1.5

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page