simperium-python3
Simperium is a simple way for developers to move data as it changes, instantly and automatically. This is the Python library. You can browse the documentation.
You can sign up for a hosted version of Simperium. There are Simperium libraries for other languages too.
This is not yet a full Simperium library for parsing diffs and changes. It's a wrapper for our HTTP API intended for scripting and basic backend development.
About this fork
This is a Python 3 fork of https://github.com/Simperium/simperium-python.
Ported and maintained by Samuel Walladge.
The following changes were done from the original python 2 version:
- 2to3
- use
requestsinstead of urllib - don't catch any http errors; clients can handle that
- add type hints
- update setup.py
Installing
pip install Simperium3
Developing
Set up an environment and install the requirements:
python -m venv venv
source venv/bin/activate
pip install -r requirements.txt
pip install -r requirements-dev.txt
Check for code quality issues (formatting and type checking):
make lint
Run integration tests.
Put the following in .env (with your actual client credentials; the api key must allow creating users):
export SIMPERIUM_CLIENT_TEST_APPNAME="foo-bar-123"
export SIMPERIUM_CLIENT_TEST_APIKEY="<app api key>"
Then:
make test
Format all the code consistently:
make fmt
Examples
A bunch of examples are included in the examples/ directory. Run them like so:
python examples/simpletodo list app-name-123 myusertoken
etc.
Getting Started
Note: these instructions have not been updated for the python3 fork.
To get started, first log into https://simperium.com and create a new application. Copy down the new app's name, api key and admin key.
Next install the python client:
$ sudo pip install git+https://github.com/Simperium/simperium-python.git
Start python and import the lib:
$ python
>>> from simperium.core import Auth, Api
We'll need to create a user to be able to store data:
>>> auth = Auth(yourappname, yourapikey)
>>> token = auth.create('joe@example.com', 'secret')
>>> token
'25c11ad089dd4c18b84f24bc18c58fe2'
We can now store and retrieve data from simperium. Data is stored in buckets. For example, we could store a list of todo items in a todo bucket. When you store items, you need to give them a unique identifier. Uuids are usually a good choice.
>>> import uuid
>>> api = Api(yourappname, token)
>>> todo1_id = uuid.uuid4().hex
>>> api.todo.post(todo1_id,
{'text': 'Read general theory of love', 'done': False})
We can retrieve this item:
>>> api.todo.get(todo1_id)
{'text': 'Read general theory of love', 'done': False}
Store another todo:
>>> api.todo.post(uuid.uuid4().hex,
{'text': 'Watch battle royale', 'done': False})
You can retrieve an index of all of a buckets items:
>>> api.todo.index()
{
'count': 2,
'index': [
{'id': 'f6b680f8504c4e31a0e54a95401ffca0', 'v': 1},
{'id': 'c0d07bb7c46e48e693653425eca93af9', 'v': 1}],
'current': '4f8507b8faf44720dfc432b1',}
Retrieve all the docuemnts in the index:
>>> [api.todo.get(x['id']) for x in api.todo.index()['index']]
[
{'text': 'Read general theory of love', 'done': False},
{'text': 'Watch battle royale', 'done': False}]
It's also possible to get the data for each document in the index with data=True:
>>> api.todo.index(data=True)
{
'count': 2,
'index': [
{'id': 'f6b680f8504c4e31a0e54a95401ffca0', 'v': 1,
'd': {'text': 'Read general theory of love', 'done': False},},
{'id': 'c0d07bb7c46e48e693653425eca93af9', 'v': 1,
'd': {'text': 'Watch battle royale', 'done': False},}],
'current': '4f8507b8faf44720dfc432b1'}
To update fields in an item, post the updated fields. They'll be merged with the current document:
>>> api.todo.post(todo1_id, {'done': True})
>>> api.todo.get(todo1_id)
{'text': 'Read general theory of love', 'done': True}
Simperium items are versioned. It's possible to go back in time and retrieve previous versions of documents:
>>> api.todo.get(todo1_id, version=1)
{'text': 'Read general theory of love', 'done': False}
Of course, you can delete items:
>>> api.todo.delete(todo1_id)
>>> api.todo.get(todo1_id) == None
True
>>> api.todo.index()['count']
1
License
The Simperium Python library is available for free and commercial use under the MIT license.
Metadata
Release files for Simperium3 0.1.5
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| Simperium3-0.1.5.tar.gz | 11.4 kB | Without provenance | Details for Simperium3-0.1.5.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| Simperium3-0.1.5-py3-none-any.whl | Python 3 | none | any | Details for Simperium3-0.1.5-py3-none-any.whl |
Total release size: 23.4 kB
Release files / Simperium3-0.1.5.tar.gz
| Download URL | Simperium3-0.1.5.tar.gz |
|---|---|
| Size | 11.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
78b8186be18869ad5fd85e83dd50ec2b94ad4f473d0f6d9f9de398a10114d137
|
|
BLAKE2b-256 checksum How to use checksums |
dde19df1f37d87085ad4451b873e3a066f2164a8cae107a5dd0ec1e1d384d0c8
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.4.2 importlib_metadata/4.6.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.59.0 CPython/3.9.6
|
Release files / Simperium3-0.1.5-py3-none-any.whl
| Download URL | Simperium3-0.1.5-py3-none-any.whl |
|---|---|
| Size | 12.0 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
a4dca0d7af8a198e7b96cbdf11d1dce2607359f855350f385265ca861c9c8f3e
|
|
BLAKE2b-256 checksum How to use checksums |
9526b2dfc412b2671811892341f7cab570dce078905900d75f23903708963195
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.4.2 importlib_metadata/4.6.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.59.0 CPython/3.9.6
|
Security for Simperium3 0.1.5
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.