Skip to main content

autosmith

Make tools quickly

Install

You must have docker installed and running.

pip install autosmith

Usage

The package will inspect a python function, its imports, argument types, and start a container that serves it on an endpoint.

from autosmith.smith import smith
import requests

def hello():
    """Return hello"""
    return 'hello'

with smith(hello) as env:
    r = requests.get(env.url + '/hello')
    print(r.text)
    # 'hello'

By default, the container will be removed when returned ToolEnv (env below) is garbage collected. You can keep the container via env.save(). You can then load via env.load().

def double(x: int):
    """Double an integer"""
    return x * 2

env = smith(double)
url = env.url + '/double?x=2'
r = requests.get(url)
print(r.text)
# 4

env.name = 'myenv'
env.save()
del env

r = requests.get(url)
print(r.text)
# 4

env = ToolEnv.load('myenv')

# now the container will be removed since we didn't save
del env

The ToolEnv object is meant to collect functions and slowly build up an environment. Note that the functions you define need not be executable in your python environment.

def nparange(n: int):
    """Return a numpy array"""
    import numpy as np
    # can only output standard python types
    return np.arange(n).astype(int).tolist()

def double(x: int):
    """Double an integer"""
    return x * 2

env = smith(nparange)
env = smith(double, env=env)

r = requests.get(env.url + '/nparange?n=5')
print(r.text)
# [0, 1, 2, 3, 4]
env.close() # another way to close the container

Metadata

Release files for autosmith 0.0.2

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

Source distribution (sdist)

Source distribution for autosmith 0.0.2
File Size Uploaded
autosmith-0.0.2.tar.gz 13.9 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for autosmith 0.0.2
File Interpreter ABI Platform
autosmith-0.0.2-py3-none-any.whl Python 3 none any Details

Total release size: 27.6 kB

Release files / autosmith-0.0.2.tar.gz

Download URL autosmith-0.0.2.tar.gz
Size 13.9 kB
Tags Source
SHA-256 checksum
How to use checksums
0e002ac57ea774dafeac3cd8ab1223f7e4894e2c096de7bd8de6fd0fbedf2618
BLAKE2b-256 checksum
How to use checksums
4e92a120ace915d6d26e2760d91b4fe90aedf316d5a0be973af8323e59437d62
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.9.17

Release files / autosmith-0.0.2-py3-none-any.whl

Download URL autosmith-0.0.2-py3-none-any.whl
Size 13.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
7be3d6e1bce81ccdf084326aed40c8f26a687efbe2820f59e5c51075b09e34e2
BLAKE2b-256 checksum
How to use checksums
507ceda9b7a2e1c18f85162a5099f28e21c42655900f1ab4535760f7948c7999
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.9.17

Release history Release notifications | RSS feed

This release

0.0.2 This release

2 release files

0.0.1

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