This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
"""A simple example of a hug API call with versioning""" | |
import hug | |
@hug.get('/echo', versions=1) | |
def echo(text): | |
return text | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
"""An example of writing an API to scrape hacker news once, and then enabling usage everywhere""" | |
import hug | |
import requests | |
@hug.local() | |
@hug.cli() | |
@hug.get() | |
def top_post(section: hug.types.one_of(('news', 'newest', 'show'))='news'): | |
"""Returns the top post from the provided section""" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/setup.py b/setup.py | |
index 21e9470..ecf9b6a 100644 | |
--- a/setup.py | |
+++ b/setup.py | |
@@ -17,7 +17,8 @@ import codecs | |
import sys | |
import unittest | |
-from setuptools import setup, Command | |
+from setuptools import Command |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/build_scripts/build.py b/build_scripts/build.py | |
index bff729f5..5659a569 100755 | |
--- a/build_scripts/build.py | |
+++ b/build_scripts/build.py | |
@@ -15,6 +15,7 @@ import sys | |
import build_utils | |
import py27 | |
+ | |
def parse_args(): |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/absl/_enum_module.py b/absl/_enum_module.py | |
index 899c488..c12e1d8 100644 | |
--- a/absl/_enum_module.py | |
+++ b/absl/_enum_module.py | |
@@ -41,6 +41,7 @@ the following is true: | |
""" | |
# pylint: disable=unused-import | |
import sys | |
+ | |
import six |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Using uwsgi | |
uwsgi --http 0.0.0.0:8000 --wsgi-file first_step_3.py --callable __hug_wsgi__ | |
# Or, using gunicorn | |
gunicorn first_step_3:__hug_wsgi__ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os | |
import hug | |
import my_internal_hug_microservice | |
if os.environ.get('API_INTERFACE', None) == 'HTTP':: | |
internal_hug_microservice = hug.use.HTTP('http://localhost:8000/') | |
else: | |
internal_hug_microservice = hug.use.Local(my_internal_hug_microservice) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from sh import zfs_scrub, do_scrub | |
@hug.cli() | |
def do_scrub(): | |
for output in zfs_scrub(''): | |
cache.set('key', output.split('%')[0].split(' ')[-1]) | |
cache.set('key', 'done') | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@hug.cli(validate=contains_one_of('argument_one', 'argument_two')) # you can combine these to make more then one mutually exclusive group | |
def mutually_exclusive_group(argument_one: type, argument_two: type): | |
pass |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import sys | |
with open(sys.argv[1]) as file: | |
print(file.read()) | |
NewerOlder