Make tools quickly automatically
Project description
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
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file autosmith-0.0.2.tar.gz
.
File metadata
- Download URL: autosmith-0.0.2.tar.gz
- Upload date:
- Size: 13.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.9.17
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0e002ac57ea774dafeac3cd8ab1223f7e4894e2c096de7bd8de6fd0fbedf2618 |
|
MD5 | 01959537a2647275bae079894412b6a5 |
|
BLAKE2b-256 | 4e92a120ace915d6d26e2760d91b4fe90aedf316d5a0be973af8323e59437d62 |
File details
Details for the file autosmith-0.0.2-py3-none-any.whl
.
File metadata
- Download URL: autosmith-0.0.2-py3-none-any.whl
- Upload date:
- Size: 13.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.9.17
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7be3d6e1bce81ccdf084326aed40c8f26a687efbe2820f59e5c51075b09e34e2 |
|
MD5 | d0c22a5a1afaf10e35dacdce4b14f3ef |
|
BLAKE2b-256 | 507ceda9b7a2e1c18f85162a5099f28e21c42655900f1ab4535760f7948c7999 |