The python API is deprecated
$ pip install space-api-pyThe complete documentation can be found here.
fromspace_apiimportAPI, AND, OR, CONDapi=API('demo-project', 'localhost:4124')
# For MongoDBdb=api.mongo()
# For PostgresQLdb=api.postgres()
# For MySQLdb=api.my_sql()Note: Multiple databases may be used simultaneously.
response=db.insert('books').doc({"name": "MyBook", "author": "John Doe"}).apply()
ifresponse.status==200:
# Record successfully insertedprint("Success")
else:
# An error occurredprint(response.error)response=db.get('books').sort('-author').apply()
ifresponse.status==200:
# We got some resultprint(response.result)
else:
# An error occurredprint(response.error)response=db.update_one('books').where(COND("author", "==", "some_author")).set({"author": "myself"}).apply()
ifresponse.status==200:
# Record successfully updatedprint("Success")
else:
# An error occurredprint(response.error)response=db.delete('books').where(COND('name', '!=', 'Book_name')).apply()
ifresponse.status==200:
# Record successfully deletedprint("Success")
else:
# An error occurredprint(response.error)b=db.begin_batch()
b.add(db.insert('books').doc({"name": "MyBook", "author": "John Doe"}))
b.add(db.insert('books').docs([{"name": "BookName"}, {"name": "BookName"}]))
b.add(db.delete('books').where(COND('name', '!=', 'Book_name')))
response=b.apply()
ifresponse.status==200:
# Record successfully made the changesprint("Success")
else:
# An error occurredprint(response.error)response=api.call('test_engine', 'test_func', 'params')
print(response)response=db.sign_in("user_email", "user_password")
ifresponse.status==200:
print(response.result)
else:
print(response.error)response=db.sign_up("user_email", "user_name", "user_password", "user_role")
ifresponse.status==200:
print(response.result)
else:
print(response.error)response=db.profile("user_id")
ifresponse.status==200:
print(response.result)
else:
print(response.error)response=db.profiles()
ifresponse.status==200:
print(response.result)
else:
print(response.error)response=db.edit_profile("user_id", email="new_email", name="new_name", password="new_password")
ifresponse.status==200:
print(response.result)
else:
print(response.error)Aliabbas Merchant - Initial work
Copyright 2019 Space Up Technologies
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.