Skycoin Python Library
Project description
[![Build Status](https://travis-ci.org/skycoin/pyskycoin.svg?branch=develop)](https://travis-ci.org/skycoin/pyskycoin)
Python extension for Skycoin API.
A Python extension generated with SWIG to access Skycoin API from Python.
## Table of Contents
<!-- MarkdownTOC levels="1,2,3,4,5" autolink="true" bracket="round" -->
- [Installation](#installation)
- [Using the API](#usage)
- [Naming](#naming)
- [Parameters](#parameters)
- [Handles](#handles)
- [Byte Slices](#byte-slices)
- [Structures](#structures)
- [Fixed Size Arrays](#fixed-size-array)
- [Other Slices](#other-slices)
- [Memory Managemanet](#memory-management)
- [Make rules](#make-rules)
- [Development setup](#development-setup)
- [Running tests](#running-tests)
- [Releases](#releases)
- [Update the version](#update-the-version)
- [Pre-release testing](#pre-release-testing)
- [Creating release builds](#creating-release-builds)
<!-- /MarkdownTOC -->
## Installation
Download the repository from http://github.com/simelo/pyskycoin.git.
Execute (`python setup.py install`) to install the library. Although executing (python setup.py develop) is a better choice for making changes to the library. However, when using tox these commands are not required at all because calling tox will make any necessary installation and execute the tests.
## Usage
### Naming
The exported function in PySkycoin have the following naming format: `SKY_package_func_name` where package is replace by the package where the original Skycoin function is and func_name is the name of the function. For example, `LoadConfig` function from `cli` package is called in Python `SKY_cli_LoadConfig`
### Parameters
All skycoin exported functions return an error object as the last of the return parameters. In Pyskycoin error is return as an integer and it is the first return parameter. The rest of the parameters are returned in the same order.
Receivers in Skycoin are the first of the input parameters. Simple types, like integer, float, string will be used as the corresponding types in Python.
#### Handles
Some of Skycoin types are too complex to be exported to a scripting language. So, handles are used instead. Therefore all functions taking a complex type will receive a handle instead of the original Skycoin type. For example, having these functions exported from Skycoin:
```go
func LoadConfig() (Config, error)
func (c Config) FullWalletPath() string
```
Config is a struct type that is treated as a handle in Pyskycoin. The usage in Python will be:
```python
import skycoin
def main:
err, configHandle = skycoin.SKY_cli_LoadConfig()
if err == skycoin.SKY_OK: # 0 then no error
fullWalletPath = skycoin.SKY_cli_FullWalletPath(configHandle)
print fullWallerPath
#Close the handle after using the it
#so the garbage collector can delete the object associated with it.
skycoin.SKY_handle_close( configHandle )
else:
#Error
print err
```
#### Byte slices
Parameters of type byte[] will treated as string . Example, this function in Skycoin:
```go
func (s ScryptChacha20poly1305) Encrypt(data, password []byte) ([]byte, error)
```
Will be called like this:
```python
encrypt_settings = skycoin.encrypt__ScryptChacha20poly1305()
data = "Data to encrypt" #It will be passed as a parameter of type []byte
pwd = "password" #As []byte too
err, encrypted = skycoin.SKY_encrypt_ScryptChacha20poly1305_Encrypt(encrypt_settings, data, pwd)
if err == skycoin.SKY_OK:
print encrypted #Encrypted is string
```
#### Structures
Structures that are not exported as handles are treated like classes in Python. In the previous example type ScryptChacha20poly1305 is created in Python like:
```python
encrypt_settings = skycoin.encrypt__ScryptChacha20poly1305()
```
And passed as first parameter in call to SKY_encrypt_ScryptChacha20poly1305_Encrypt.
#### Fixed Sized Arrays
Parameters of fixed size array are wrapped in structures when called from python.
Given these types in Skycoin:
```go
type PubKey [33]byte
type SecKey [32]byte
```
And this exported function:
```go
func GenerateDeterministicKeyPair(seed []byte) (PubKey, SecKey)
```
This is how it is used in Python:
```python
#Generates random seed
err, data = skycoin.SKY_cipher_RandByte(32)
assert err == error["SKY_OK"]
pubkey = skycoin.cipher_PubKey()
seckey = skycoin.cipher_SecKey()
err = skycoin.SKY_cipher_GenerateDeterministicKeyPair(data, pubkey, seckey)
```
pubkey and seckey are objects of type structure containing a field name data for the corresponding type of PubKey and SecKey. Something like:
```cpp
cipher_PubKey struct{
data [33]byte;
} cipher_PubKey;
cipher_SecKey struct{
data [32]byte;
} ;
```
#### Other Slices
Other slices of type different than byte were wrapped inside classes. Calling the following function:
```go
func GenerateDeterministicKeyPairs(seed []byte, n int) []SecKey
```
Would be like:
```python
#Generates random seed
err, seed = skycoin.SKY_cipher_RandByte(32)
err, seckeys = skycoin.SKY_cipher_GenerateDeterministicKeyPairs(seed, 2)
for seckey in seckeys:
pubkey = skycoin.cipher_PubKey()
skycoin.SKY_cipher_PubKeyFromSecKey(seckey, pubkey)
err = skycoin.SKY_cipher_PubKey_Verify(pubkey)
assert err == error["SKY_OK"]
```
### Memory Management
Memory management is transparent to the user. Any object allocated inside the library is left to be managed by Python garbage collector.
## Make Rules
All these make rules require skycoin to be a git submodule of pyskycoin
- build-libc
* Compiles skycoin C language library.
- build-swig
* Creates the wrapper C code to generate the Python library.
- develop
* Install a developer version of the module.
- test
* Compiles skycoin C language library, creates the wrapper and execute Tox. Tox installs compiles the Python library and executes the tests.
## Development setup
It is highly recommended for developers to setup their environment using
the available Docker images.
Read the [PySkycoin Docker docs](docker/images/dev-cli/README.md) for further
details.
The project has two branches: `master` and `develop`.
- `develop` is the default branch and will always have the latest code.
The submodule at `gopath/src/github.com/skycoin/skycoin` has to be
in sync with `skycoin/skycoin` `develop` branch.
- `master` will always be equal to the current stable release on the website, and should correspond with the latest release tag.
The submodule at `gopath/src/github.com/skycoin/skycoin` has to be
in sync with `skycoin/skycoin` `master` branch.
Separate stable development branches will be created to work on releases for supporting the
most recent stable version of Skycoin. The name of these branches should be the Skycoin
major and minor version numbers followed by `dev` suffix e.g. `0.25dev`.
These branches may be forked out of either `master` or `develop` branches, and
the submodule at `gopath/src/github.com/skycoin/skycoin` has to be
in sync with the corresponding tag of `skycoin/skycoin` official repository.
Stable development branches are created most of the time for the following reasons:
- A Skycoin release increasing [patch version number](https://semver.org/).
- Enhanced support and bug fixes for a version of PySkycoin compiled against an
stable version of Skycoin
- Backporting useful features added in `develop`.
### Running tests
```sh
$ make test
```
### Releases
#### Update the version
0. If the `master` branch has commits that are not in `develop` (e.g. due to a hotfix applied to `master`), merge `master` into `develop` (and fix any build or test failures)
0. Switch to a new release branch named `release-X.Y.Z` for preparing the release.
0. Ensure that the submodule at `gopath/src/github.com/skycoin/skycoin` is in sync with respect to the corresponding tag in https://github.com/skycoin/skycoin repository.
0. Update `__version__` in `skycoin/__init__.py`
0. Run `make build` to make sure that the code base is up to date
0. Update `CHANGELOG.md`: move the "unreleased" changes to the version and add the date.
0. Follow the steps in [pre-release testing](#pre-release-testing)
0. Make a PR merging the release branch into `master`
0. Review the PR and merge it
0. Update files in https://github.com/skycoin/repo-info/tree/master/repos/skycoin/remote for `simelotech/skycoindev-dotnet` Docker image, adding a new file for the new version and adjusting any configuration text that may have changed
0. Tag the `master` branch with the version number. Version tags start with `v`, e.g. `v0.20.0`. Sign the tag. If you have your GPG key in github, creating a release on the Github website will automatically tag the release. It can be tagged from the command line with `git tag -as v0.20.0 $COMMIT_ID`, but Github will not recognize it as a "release".
0. Release builds are created and uploaded by travis. To do it manually, checkout the master branch and follow the [create release builds instructions](#creating-release-builds).
0. Checkout `develop` branch and bump `__version__` to next [`dev` version number](https://www.python.org/dev/peps/pep-0440/#developmental-releases).
#### Pre-release testing
Perform these actions before releasing:
```sh
make check
make integration-test
```
#### Creating release builds
Release builds should be created from git tags . After [updating release version](#update-the-version) it is necessary to follow these steps
```sh
cd /path/to/pyskycoin
python3 setup.py sdist bdist_wheel
python3 -m pip install --user --upgrade twine
twine upload --repository-url https://test.pypi.org/legacy/ dist/*
```
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 Distributions
Built Distributions
File details
Details for the file pyskycoin-0.25.0-cp37-cp37m-manylinux1_x86_64.whl
.
File metadata
- Download URL: pyskycoin-0.25.0-cp37-cp37m-manylinux1_x86_64.whl
- Upload date:
- Size: 585.8 kB
- Tags: CPython 3.7m
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.11.0 pkginfo/1.4.2 requests/2.19.1 setuptools/40.0.0 requests-toolbelt/0.8.0 tqdm/4.24.0 CPython/3.4.8
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0dd07ab34df02b0803ca51397983b1e04eb5aaba23255deb214ebcac8bdf42eb |
|
MD5 | ca2eae3643980af255ab63cec5bd3dd9 |
|
BLAKE2b-256 | c6c3637dcc464f8e38890447ea3aaea223adb65bbd314a164222db51f067fec6 |
File details
Details for the file pyskycoin-0.25.0-cp37-cp37m-macosx_10_13_x86_64.whl
.
File metadata
- Download URL: pyskycoin-0.25.0-cp37-cp37m-macosx_10_13_x86_64.whl
- Upload date:
- Size: 4.4 MB
- Tags: CPython 3.7m, macOS 10.13+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.12.1 pkginfo/1.5.0.1 requests/2.21.0 setuptools/40.6.3 requests-toolbelt/0.8.0 tqdm/4.29.1 CPython/3.7.1
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 48b47fe09c479cedf58defe505ab591ac8c2cc3abebd0564b66a2e5364869c93 |
|
MD5 | 31ad5776ed90748fb24ac65afe3a9976 |
|
BLAKE2b-256 | 94715a8d8600da3cec983a38fa00627f8418bf4d9c98f8af4947ef07767768a7 |
File details
Details for the file pyskycoin-0.25.0-cp36-cp36m-manylinux1_x86_64.whl
.
File metadata
- Download URL: pyskycoin-0.25.0-cp36-cp36m-manylinux1_x86_64.whl
- Upload date:
- Size: 585.8 kB
- Tags: CPython 3.6m
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.11.0 pkginfo/1.4.2 requests/2.19.1 setuptools/40.0.0 requests-toolbelt/0.8.0 tqdm/4.24.0 CPython/3.4.8
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 69c4dea72cf3abfd30e3541ca792e04a635f27f85d7895ce1bae6b9e87abd14e |
|
MD5 | 93d685bbe3d5c1429f09f63f5ce76e4a |
|
BLAKE2b-256 | c3d55a860e71c4da7718a46165b027f23e57135853fdc79a4a55c35d7499f015 |
File details
Details for the file pyskycoin-0.25.0-cp36-cp36m-macosx_10_13_x86_64.whl
.
File metadata
- Download URL: pyskycoin-0.25.0-cp36-cp36m-macosx_10_13_x86_64.whl
- Upload date:
- Size: 4.4 MB
- Tags: CPython 3.6m, macOS 10.13+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.12.1 pkginfo/1.5.0.1 requests/2.21.0 setuptools/40.6.3 requests-toolbelt/0.8.0 tqdm/4.29.1 CPython/3.6.5
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | dc4d6c51bad38725d3edbf432229050794415be5c00940867a93d01841adb0bc |
|
MD5 | 03c51f84800da79ee88b368495e6b8a1 |
|
BLAKE2b-256 | f51ec9ba08de6f0e1b025dba2ff1e87d3f9907d8071420c3790901951fc28184 |
File details
Details for the file pyskycoin-0.25.0-cp35-cp35m-manylinux1_x86_64.whl
.
File metadata
- Download URL: pyskycoin-0.25.0-cp35-cp35m-manylinux1_x86_64.whl
- Upload date:
- Size: 585.8 kB
- Tags: CPython 3.5m
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.11.0 pkginfo/1.4.2 requests/2.19.1 setuptools/40.0.0 requests-toolbelt/0.8.0 tqdm/4.24.0 CPython/3.4.8
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | ace5316238caa410802e7c028345bbb550b30c441a15dab2672cf47b81eb0a07 |
|
MD5 | fe1a40e8d89450656d13b5982d56cb92 |
|
BLAKE2b-256 | 35c8341758865e2fcadcfa7612f6bb3f6b13bcc0efbe1434bb733d067ccf4a41 |
File details
Details for the file pyskycoin-0.25.0-cp35-cp35m-macosx_10_13_x86_64.whl
.
File metadata
- Download URL: pyskycoin-0.25.0-cp35-cp35m-macosx_10_13_x86_64.whl
- Upload date:
- Size: 4.4 MB
- Tags: CPython 3.5m, macOS 10.13+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.12.1 pkginfo/1.5.0.1 requests/2.21.0 setuptools/40.6.3 requests-toolbelt/0.8.0 tqdm/4.29.1 CPython/3.5.5
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7d3562aaa99738ad4013b152c2471bdf27d8fdeb57708fdbda0ee30e75544c18 |
|
MD5 | d49e2166eafe42b3a33d16809412a506 |
|
BLAKE2b-256 | 6b246c3d120e6ffaaf97ca1caf19661be2464106f976fc646a97b54034b08ef5 |
File details
Details for the file pyskycoin-0.25.0-cp34-cp34m-manylinux1_x86_64.whl
.
File metadata
- Download URL: pyskycoin-0.25.0-cp34-cp34m-manylinux1_x86_64.whl
- Upload date:
- Size: 585.6 kB
- Tags: CPython 3.4m
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.11.0 pkginfo/1.4.2 requests/2.19.1 setuptools/40.0.0 requests-toolbelt/0.8.0 tqdm/4.24.0 CPython/3.4.8
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 18ac1ffd3be8d20391eb7925a01d7dfbeb4ed9cccf3274e986845a20a8afb9ca |
|
MD5 | c13df2b16ad02c5129435386b894efdc |
|
BLAKE2b-256 | 13135625e16bb093933e79d8e57657562b4afc10cb952eecda7de43b79685d18 |
File details
Details for the file pyskycoin-0.25.0-cp34-cp34m-macosx_10_13_x86_64.whl
.
File metadata
- Download URL: pyskycoin-0.25.0-cp34-cp34m-macosx_10_13_x86_64.whl
- Upload date:
- Size: 4.4 MB
- Tags: CPython 3.4m, macOS 10.13+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.12.1 pkginfo/1.5.0.1 requests/2.21.0 setuptools/40.6.3 requests-toolbelt/0.8.0 tqdm/4.29.1 CPython/3.4.8
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 462ce0a609373dae39d398c8827b87aff6630e47412c1a8898b63fca266280e0 |
|
MD5 | ab040cad844c9f81875ea5c2b06cd07a |
|
BLAKE2b-256 | dbc7ce8c14a682f8049d1d2a236f8a0a9e186dc6e06c2332c5d60b680ba2fdd7 |
File details
Details for the file pyskycoin-0.25.0-cp27-cp27mu-manylinux1_x86_64.whl
.
File metadata
- Download URL: pyskycoin-0.25.0-cp27-cp27mu-manylinux1_x86_64.whl
- Upload date:
- Size: 598.0 kB
- Tags: CPython 2.7mu
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.11.0 pkginfo/1.4.2 requests/2.19.1 setuptools/40.0.0 requests-toolbelt/0.8.0 tqdm/4.24.0 CPython/3.4.8
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 311779ee42cf1bb256842ef02eb34bac9d3cccddc508e231360d977d26584d0b |
|
MD5 | 3d14387ad528b72fd8d1f8a98a9706da |
|
BLAKE2b-256 | 88cb16cb3c7c04987420c4df7565892f55946a280d27ad2809d1d3a6efd8ffcf |
File details
Details for the file pyskycoin-0.25.0-cp27-cp27m-manylinux1_x86_64.whl
.
File metadata
- Download URL: pyskycoin-0.25.0-cp27-cp27m-manylinux1_x86_64.whl
- Upload date:
- Size: 597.9 kB
- Tags: CPython 2.7m
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.11.0 pkginfo/1.4.2 requests/2.19.1 setuptools/40.0.0 requests-toolbelt/0.8.0 tqdm/4.24.0 CPython/3.4.8
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9c37c5e9c8f110e5d17866acc43da4e638872f684f5317eccf7624bc07231d44 |
|
MD5 | 883a0426f3eabbd6de7d415871d8d8e6 |
|
BLAKE2b-256 | 02e990dd0f6d2bd57fc8c1e8e877e7d3ac8ec038a7d8a3ffb2761d3317b6a388 |
File details
Details for the file pyskycoin-0.25.0-cp27-cp27m-macosx_10_13_x86_64.whl
.
File metadata
- Download URL: pyskycoin-0.25.0-cp27-cp27m-macosx_10_13_x86_64.whl
- Upload date:
- Size: 4.4 MB
- Tags: CPython 2.7m, macOS 10.13+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.12.1 pkginfo/1.5.0.1 requests/2.21.0 setuptools/40.6.3 requests-toolbelt/0.8.0 tqdm/4.29.1 CPython/2.7.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | be0a924660e097d26868efc3e725d0da6c74e9b07807ceb49d8beead314e5d0b |
|
MD5 | f10d1bee5e808a2b7a5671e07d620188 |
|
BLAKE2b-256 | 7027e5a4c2a4d87ba50a569ce18fbbe0603bb7e9c4cf2c9b0f0d3a85861ffda2 |