Package: hyper-connect
🐍 hyper-connect 🐍hyper-connectis the python SDK package forhyper.Official hyperdocumentation.InstallUsageServices and Actionshyper vision 😎Types and type checkingExamplesSynchronous and asynchronous supportAsync examplesContributingLicenseCode of ConductLintingTestsTag and ReleaseBuildPublishing to TestPyPIPublishing to PyPIInstallThe following command will install the latest version of thehyper-connectmodule and its dependencies from the Python Packaging Index (PyPI):pip install hyper-connectUsagehyper-connectwraps a hyper app's REST API, generating a short-lived JWT using aconnection stringfrom one of your hyper app's app keys.hyper-connectsupports both synchronous and asynchronous calls.Once you've created an environment variable namedHYPERwith the value of a connection string, you're ready to make a call to theconnectfunction which returns aHyperobject:fromhyper_connectimportconnectfromhyper_connect.typesimportHyperfromdotenvimportdotenv_valuesfromtypingimportDictconfig=dotenv_values("./.env")connection_string:str=str(config["HYPER"])hyper:Hyper=connect(connection_string)movie:Dict={"_id":"movie-4000","type":"movie","title":"Back to the Future","year":"1985",}result=hyper.data.add(movie)print("hyper.data.add result --> ",result)# hyper.data.add result -->  {'id': 'movie-4000', 'ok': True, 'status': 201}Services and Actionshyper is a suite of service apis, with hyper connect you can specify the API you want to connect with and the action you want to perform.
hyper.[service].[action] - with each service there are a different set of actions to call. This table breaks down the service and action with description of the action.dataServiceActionDescriptiondataaddcreates a json document in the hyper data storedatalistlists the documents given a start,stop,limit rangedatagetretrieves a document by iddataupdateupdates a given document by iddataremoveremoves a document from the storedataqueryqueries the store for a set of documents based on selector criteriadataindexcreates an index for the data storedatabulkinserts, updates, and removed document via a batch of documentscacheServiceActionDescriptioncacheaddcreates a json document in the hyper cache store with a keycachegetretrieves a document by keycachesetsets a given document by keycacheremoveremoves a document from the cachecachequeryqueries the cache for a set of documents based on a pattern matchersearchServiceActionDescriptionsearchaddindexes a json document in the hyper search indexsearchgetretrieves a document from indexsearchupdateupdates a document in the hyper search indexsearchremoveremoves a document from the indexsearchquerysearches index by textsearchloadloads a batch of documentsstorageServiceActionDescriptionstorageuploadadds object/file to hyper storage bucketstoragedownloadretrieves a object/file from bucketstorageremoveremoves a object/file from the bucketqueueServiceActionDescriptionqueueenqueueposts object to queuequeueerrorsgets list of errors occured with queuequeuequeuedgets list of objects that are queued and ready to be sent.hyper vision 😎hyper visionis a UI dev tool to browse hyper cloud data, cache, search, etc. via an app key's connection string.  It is available athttps://vision.hyper.io/.Types and type checkingCommon types you'll encounter includeHYPER,ListOptions,QueryOptions, andSearchQueryOptions.fromhyper_connectimportconnectfromhyper_connect.typesimportHyper,ListOptions,QueryOptions,SearchQueryOptionsThe SDK performs runtime type checking on the arguments passed into methods and functions, as well as, the return value.Passing incorrect types will cause aTypeErrorto be raised:defdata_list_bad_keys_sync(self):options:ListOptions={"startkey":None,"limit":None,"endkey":None,"keys":6,"descending":None,}try:result=hyper.data.list(options)exceptTypeErroraserr:print('data_list_bad_keys_sync TypeError -> ',err)# data_list_bad_keys_sync TypeError -> type of dict item "params" for argument "req_params" must be one of (hyper_connect.types._types.ListOptions, hyper_connect.types._types.QueryOptions, Dict[str, str], NoneType); got dict insteadSome keys withinListOptions,QueryOptions, andSearchQueryOptionsare optional.  For example both of the following typed Dictionaries are valid types:valid_data_list_options:ListOptions={"startkey":"book-000105","limit":None,"endkey":"book-000106","keys":None,"descending":None,}also_valid_options:ListOptions={"startkey":"book-000105","endkey":"book-000106"}ExamplesSeeexamples.pySynchronous and asynchronous supporthyper_connectsupports both synchronous and asynchronous methods for each service type (data, cache, storage, etc.).  It's easy to distinguish between the two.  Synchronous method names willnotend in_async.```py
result = hyper.data.add(movie)
```While asynchronous methods end in_async:```py
result = await hyper.data.add_async(movie)
```Async can be a little tricky.  Here are a couple of good resources to help avoid the pitfalls 😵‍💫:How to Create an Async API Call with asyncioandCommon Mistakes Using Python3 asyncioYou must use theasyncandawaitsyntax:asyncdefdata_add():movie:Dict={"_id":"movie-5000","type":"movie","title":"Back to the Future 2","year":"1987",}result:IdResult=awaithyper.data.add_async(movie)print("hyper.data.add_async result --> ",result)# hyper.data.add_async result -->  {'id': 'movie-4000', 'ok': True, 'status': 201}To run your asyncronous function, useasynciowhich is a library to write concurrent code using the async/await syntax:fromexamples_asyncimportdata_addimportasyncioasyncio.run(data_add())# hyper.data.add result -->  {'id': 'movie-5000', 'ok': True, 'status': 201}Calls to asynchronous methods return JS style promises.  Compose your Hyper services to create complex flows:asyncdefdata_cache_compose():movie:Dict={"_id":"movie-5001","type":"movie","title":"Back to the Future 3","year":"1989",}result=awaithyper.data.add_async(movie).then(lambda_:hyper.cache.add_async(key=movie["_id"],value=movie,ttl="1d"))print("hyper data and cache add result --> ",result)# hyper data and cache add_async result -->  {'ok': True, 'status': 201}Async examplesSeeexamples_async.pyContributingInterested in contributing? Check out the contributing guidelines. Please note that this project is released with a Code of Conduct. By contributing to this project, you agree to abide by its terms.SeeContributing.Licensehyper_connectwas created by the hyper team. It is licensed under the terms of the Apache 2.0 license.SeeLicence.Code of Conduct.
SeeCode of ConductDeveloper SetupWe prefer you use Gitpod.  Gitpod provides a fully initialized, perfectly set-up developer environmment for the hyper connect SDK.We recommend youinstall the Gitpod browser extensionto make this a one-click operation.Environment VariablesIf you plan on running tests, you'll need to create an environment variable namedHYPER.HYPER=cloud://yourappkey:yourappsecret--gI1MkcrUqFPMR@cloud.hyper.io/express-quickstartOne way to add an environment variable is to use a.envfile.  Feel free to provide environment variables in a way that makes sense to you.Create a.envfile in the project root.Within.env, create an environment variable namedHYPERwith a value of your hyper app'sconnection string.LintingWe use git pre-commit hooks, black, and isort to prettify the code and run static type checking with mypy.   See the.pre-commit-config.yaml.To run these checks, execute themake lintcommand.TestsHeads up! Integration tests assume a hyper app and services have been created.  Seehttps://docs.hyper.io/applicationsfor details on creating hyper applications and service.A storage service should have the following setup:Run themake testscript to run the unit and integration tests.Tag and ReleaseBump the semver value withinpyproject.toml.  Create tag and push tag:$gittagv0.0.3
$gitpush--tagsNow if you go to the repository on GitHub and navigate to the “Releases” tab, you should see the new tag.Create a release from the tag in GitHub.Seehttps://py-pkgs.org/03-how-to-package-a-python#tagging-a-package-release-with-version-controlBuildWe can easily create an sdist and wheel of a package with poetry using the commandpoetry build.  Both files are created in a directory nameddist/.  Those two new files are the sdist and wheel for our package.$poetrybuildSeehttps://py-pkgs.org/03-how-to-package-a-python#building-your-packagePublishing to TestPyPIDo a “dry run” and check that everything works as expected by submitting to TestPyPi first.poetryhas apublishcommand, which we can use to do this, however the default behavior is to publish to PyPI. So we need to add TestPyPI to the list of repositoriespoetryknows about using the following command:$poetryconfigrepositories.test-pypihttps://test.pypi.org/legacy/To publish to TestPyPI we can use poetry publish (you will be prompted for your username and password for TestPyPI).$poetrypublish-rtest-pypiNow we should be able to visit our package on TestPyPI:https://test.pypi.org/project/hyper-connect/We can try installing our package using pip from the command line with the following command:$pipinstall--index-urlhttps://test.pypi.org/simple/--extra-index-urlhttps://pypi.org/simplehyper-connectSeehttps://py-pkgs.org/03-how-to-package-a-python#publishing-to-testpypiPublishing to PyPIIf you were able to upload your package to TestPyPI and install it without error, you’re ready to publish your package to PyPI. You can publish to PyPI using thepoetry publishcommand without any arguments:$poetrypublishYour package will then be available on PyPI (e.g.,https://pypi.org/project/pycounts/) and can be installed by anyone using pip:Seehttps://py-pkgs.org/03-how-to-package-a-python#publishing-to-pypiCOMING SOON: Verify Signaturehyper Queue allows you to create a target web hook endpoint to receive jobs, in order to secure that endpoint to only receive jobs from hyper, you can implement a secret, this secret using sha256 to encode anouncetimestamp and a signature of the job payload. We created a function onhyper_connectto make it easier to implement your own middleware to validate these incoming jobs in a secure way.