Python Ulord-platform SDK documentation¶
Overview¶
Ulord-platform HTTP Client Library
Before reading the document you should pay attention to the following:
Important: The legacy py-ulord-api package/module will only work for Ulord-platform 0.0.1 and Python 2.7.
Note: This library constantly has to change to stay compatible with the Ulord-platform HTTP API. Currently, this library is tested against Ulord-platform v0.0.1. You may experience compatibility issues when attempting to use it with other versions of Ulord-platform.
Including¶
This package has three functions,including cli, py-api and web-API.
py-api is a python package.It support most functions.**Suggest you to use this**.
Cli is a simple package for python api.
Web-API is also a simple package for python package.
Featured Projects¶
waiting…
TODO list¶
- [x] add TODO list
- [ ] some docs
- [ ] support python3
- [ ] more friendly expression
- [ ] add multi-threading download
- [ ] add unit test
- [ ] docker environment
Contribute¶
Bug reports¶
You can submit bug reports using the GitHub issue tracker.
Pull requests¶
Pull requests are welcome. Before submitting a new pull request, please waiting…
Want to read this repository?¶
Some places to get you started. (WIP)
Senior programmer Main file: ulordapi/user.py
Junior Programmer Main file: ulordapi/user.py
CLI Commands: ulordapi/daemonCLI.py
Web Server: ulordapi/webServer.py
What’snew¶
waiting…
Install¶
> import: haven’t completed!
Install with pip(not completed!):
$ pip install ulordapi
Or you can use this repository to set up
git clone https://github.com/UlordChain/py-ulord-api.git
cd py-ulord-api
python setup.py install
Example¶
This is a tutorial thar uses SDK to develop a blog demo.
Get development permissions¶
You should regist on the ulord-platform.And then you need to create a application.You will get a appkey and a secret.The two things are important.You mustn’t lose them.
Init¶
Create a role according to your ability using your appkey and secret.SDK has two roles.One is junior and the other is senior.Both them have to init using your appkey and secret.
Senior has base API about UDFS and ulord-platform.UDFS is a distributed storge platform.Using it you can upload your resource and download easily.The API about ulord-platform packages fot ulord-platform http interface.
Junior has all API of Senior.And it also has a base database.You can using database whatever you want to use.Default is sqlite.It achieves base on the flask-sqlalchemy.And you can build your own database structure.
from ulordapi.user import Junior
junior = Junior(appkey="5d42b27e581c11e88b12f48e3889c8ab", secret="5d42b27f581c11e8bf63f48e3889c8ab")
Config¶
You should make your own config.Reading config module and create your own config.
blog_config = {
'baseconfig':{
'config_file':'E:\ulord\ulord-blog-demo\config'
},
'logconfig':{
'log_file_path': 'E:\ulord\ulord-blog-demo\blogdemo.log'
}
}
junior.config_edit(blog_config)
Create your required interface¶
Example regist(This demo is using flask):
@app.route('/user/regist',methods=['POST'])
def regist():
"""
user regist
:return: user token
"""
username = request.json.get('username')
password = request.json.get('password')
cellphone = request.json.get('cellphone')
email = request.json.get('email')
if username is None or password is None:
# missing arguments
return jsonify(return_result(60100))
args = junior.decrypt([username, password, cellphone, email])
if args:
result = junior.user_regist(username=args[0],password=args[1],cellphone=args[2],email=args[3])
return jsonify(result)
else:
return jsonify(return_result(60100))
ulordapi¶
udfs¶
ulordapi.udfs¶
udfs¶
-
class
ulordapi.udfs.udfs.
Udfs
[source]¶ udfs class,including some operations about daemon program
-
start
(daemon=None)[source]¶ start udfs.if daemon is true, the udfs is a daemon,else the udfs is starting the current thread.
Parameters: daemon (bool) – if wait
-
-
class
ulordapi.udfs.udfs.
UdfsHelper
(host='127.0.0.1', port='5001')[source]¶ download and upload files from Ulord
-
cat
(udfshash)[source]¶ Retrieves the contents of a file identified by hash. :param udfshash: udfs hash :type udfshash:str :return: str(File contents)
-
downloadfile
(localfile)[source]¶ query the localfile from DB and then download from the udfs
Parameters: localfile (str) – a file path Returns: True os False
-
downloadhash
(filehash, filepath=None, Debug=False)[source]¶ download file from the UDFS according to the udfs hash
Parameters: - filehash (str) – file udfs hash
- filepath (str) – the path to save the file
- Debug (bool) – if Debug print the cost time
Returns: True or False
-
list
(filehash)[source]¶ list the udfshash chunks
Parameters: filehash (str) – a udfs hash Returns: a list chunks of the udfs hash
-
resumableDownload
(filehash, filename=None)[source]¶ resumable download
Parameters: - filehash (str) – file UDFS hash
- filename (str) – file path to save the file
Returns: True or False
-
update
(host='127.0.0.1', port='5001')[source]¶ update udfs dameon connection
Parameters: - host (str) – udfs daemon host
- port (str/int) – udfs daemon port
-
config¶
-
class
ulordapi.config.
Config
(*args, **kwargs)[source]¶ Bases:
dict
config class.Based on the dict.Update key-value,including subdict.
daemonCLI¶
errcode¶
-
ulordapi.errcode.
return_result
(errcode=0, reason=None, result=None)[source]¶ update errcode,reason,result and then return
Parameters: - errcode (int) – errcode
- reason (str/dict) – reason, change it to the dict and update original reason
- result (str/dict) – result, change it to the dict and update original result
Returns: errcode result
manage¶
-
class
ulordapi.manage.
Ads
(**kwargs)[source]¶ Bases:
ulordapi.manage.Resource
Advertisement.Viewer will get a few ulord from the author when they view it.
-
UPID
¶
-
amount
¶
-
body
¶
-
claimID
¶
-
date
¶
-
description
¶
-
id
¶
-
resource_type
¶
-
title
¶
-
userid
¶
-
views
¶
-
-
class
ulordapi.manage.
Content
(**kwargs)[source]¶ Bases:
ulordapi.manage.Resource
Content,viewer need to pay a few ulord to view.
-
UPID
¶
-
amount
¶
-
body
¶
-
claimID
¶
-
date
¶
-
description
¶
-
id
¶
-
resource
¶
-
resource_type
¶
-
title
¶
-
userid
¶
-
views
¶
-
-
class
ulordapi.manage.
Resource
(**kwargs)[source]¶ Bases:
sqlalchemy.ext.declarative.api.Model
Resource table: create resource table
-
UPID
¶
-
amount
¶
-
body
¶
-
claimID
¶
-
date
¶
-
description
¶
-
id
¶
-
resource
¶
-
resource_type
¶
-
title
¶
-
userid
¶
-
views
¶
-
-
class
ulordapi.manage.
Tag
(**kwargs)[source]¶ Bases:
sqlalchemy.ext.declarative.api.Model
tag table
-
id
¶
-
pre1
¶
-
pre2
¶
-
resource
¶
-
tagname
¶
-
-
class
ulordapi.manage.
User
(**kwargs)[source]¶ Bases:
sqlalchemy.ext.declarative.api.Model
User table: create user database.
-
activity
¶
-
balance
¶
-
boughts
¶
-
cellphone
¶
-
email
¶
-
hash_password
(password)[source]¶ Hash user’s password and save hash result.
Parameters: password (str) – user’s password
-
id
¶
-
password_hash
¶
-
pay_password
¶
-
timestamp
¶
-
token
¶
-
username
¶
-
verify_password
(password)[source]¶ verify password
Parameters: password (str) – user’s password Returns: True or False.
-
wallet
¶
-
up¶
-
class
ulordapi.up.
UlordHelper
(appkey=None, ulord_secret=None)[source]¶ Bases:
object
a helper to request the ulord paltform
-
calculate_sign
(dt=None)[source]¶ encrypt the request data according to the secret
Parameters: dt (dict) – data need to be encrypted, Default is None Returns: Usign
-
checkisbought
(payer, claim_ids)[source]¶ query the personal balance from the ulord platform
Parameters: - payer (str) – payer wallet name
- claim_ids (list) – resource claim id
Returns: errcode.You can query from the errcode dict.
-
delete
(id, password)[source]¶ delete resource on the ulord-platform
Parameters: - id (int) – resource ulord-platform DB ID
- password (str) – user wallet password
Returns: errcode.You can query from the errcode dict.
-
get
(url)[source]¶ get from the ulord-platform
Parameters: url (str) – request’s url Returns: return result.You can query the errcode.
-
paytouser
(username)[source]¶ activity send some ulords to the user
Parameters: username (str) – user wallet name Returns: errcode.You can query from the errcode dict.
-
post
(url, data)[source]¶ post to the ulord-platform
Parameters: - url (str) – request’s url
- data (dict) – post data
Returns: return result.you can query the errcode
-
publish
(data)[source]¶ publish data to the ulord platform
Parameters: data (dict) – data needed to be published.Key includes author,title,tags,udfs_hash,price,content_type,des,pay_password Returns: errcode.You can query from the errcode dict.
-
queryBillingDetailByID
(claim_id, page=1, num=10)[source]¶ query all billing details according to the claimID
Parameters: - claim_id (str) – resource on the ulord-chain ID
- page (int) – which page of result do you want to view?Default is 1.
- num (int) – how many pieces of data of result do you want to view?Default is 10.
Returns: errcode.You can query from the errcode dict.
-
queryStatisticsByID
(claim_ids)[source]¶ query resource statistics information by ID
Parameters: claim_ids (list) – need to be query ID list. Returns: errcode.You can query from the errcode dict.
-
query_resourc_by_ID
(ids)[source]¶ query resource list according to the id list
Parameters: ids (list) – need to be query id list Returns: errcode.You can query from the errcode dict.
-
querybalance
(payer, pay_password)[source]¶ query the personal balance from the ulord platform
Parameters: - payer (str) – payer wallet name
- pay_password (str) – payer wallet password
Returns: errcode.You can query from the errcode dict.
-
querybillings
(username, start, end)[source]¶ get billings info
Parameters: - username (str) – current user wallet name
- start (str) – start time.2018-03-29
- end (str) – end time.2018-03-29
Returns: errcode.You can query from the errcode dict.
-
querybillingsdetail
(author, page=1, num=10)[source]¶ query the billings detail.Union the income and outgo
Parameters: - author (str) – current user wallet name
- page (int) – which page of result do you want to view?Default is 1.
- num (int) – how many pieces of data of result do you want to view?Default is 10.
Returns: errcode.You can query from the errcode dict.
-
queryincomebillings
(author, start, end, page=1, num=10, category=2)[source]¶ get income billings info
Parameters: - author (str) – current user wallet name
- start (str) – start time.2018-03-29
- end (str) – end time.2018-03-29
- page (int) – which page of result do you want to view?Default is 1.
- num (int) – how many pieces of data of result do you want to view?Default is 10.
- category (int) – resource type. 0—-common resource,1—-ads,2—–all
Returns: errcode.You can query from the errcode dict.
-
queryoutgobillings
(author, start, end, page=1, num=10, category=2)[source]¶ get outgo billings info
Parameters: - author (str) – current user wallet name
- start (str) – start time.2018-03-29
- end (str) – end time.2018-03-29
- page (int) – which page of result do you want to view?Default is 1.
- num (int) – how many pieces of data of result do you want to view?Default is 10.
- category (int) – resource type. 0—-common resource,1—-ads,2—–all
Returns: errcode.You can query from the errcode dict.
-
querypublishnum
(author, start, end)[source]¶ query the number of resourced which has published
Parameters: - author (str) – current user wallet name
- start (str) – start time.2018-03-29
- end (str) – end time.2018-03-29
Returns: errcode.You can query from the errcode dict.
-
queryresource
(page=1, num=10, **kwargs)[source]¶ query the resource list from the ulord platform.method is get
Parameters: - page (int) – which page do you want to view?Default is 1.
- num (int) – how many pieces of datas in one page?.Default is 10.
- kwargs (key-value) – key-value query
Returns: errcode.You can query from the errcode dict.
-
queryuserpublished
(wallet_username, page=1, num=10)[source]¶ query user published from ulort platform
Parameters: - wallet_username (str) – auther wallet name
- page (int) – which page of result do you want to view?Default is 1.
- num (int) – how many pieces of data of result do you want to view?Default is 10.
Returns: errcode.You can query from the errcode dict.
-
regist
(username, password)[source]¶ regist wallet address from the ulord platform
Parameters: - username (str) – wallet name
- password (str) – wallet password
Returns: errcode.You can query from the errcode dict
-
transaction
(payer, claim_id, pay_password, isads=False)[source]¶ record the transaction to the ulord platform
Parameters: - payer (str) – payer wallet name
- claim_id (str) – resource claim id
- pay_password (str) – payer wallet password
- isads (bool) – check the resource if a Ad.
Returns: errcode.You can query from the errcode dict.
-
user¶
-
class
ulordapi.user.
Developer
(appkey, secret)[source]¶ Bases:
ulordapi.up.UlordHelper
basic develoer class to execute some functions
-
config_edit
(args=None)[source]¶ config operations
Parameters: args (list/dict) – a list or a dict.Update config Returns: args dict
-
config_show
(args=None)[source]¶ show config.Default show all.
Parameters: args (list/dict) – keys Returns: config according to the keys
-
decrypt
(args)[source]¶ check if the arg is encrypted.If encrypted return decrypted arg,else return None.
Parameters: args (str/str list) – arg need to be checked, Returns: decrypted arg or arg(unicode)
-
request
(method, url, data=None)[source]¶ advanced command. request to the ulord-platform
Parameters: - method (str) – request method,like post,get and so on.
- url (str) – request url
- data (dict) – request data
Returns: return result.you can query the errcode
-
udfs_cat
(udfshashs)[source]¶ view the udfs hash comment
Parameters: udfshashs (list) – udfs hashes Returns: dict udfshash - True/False
-
-
class
ulordapi.user.
Junior
(appkey, secret)[source]¶ Bases:
ulordapi.user.Developer
Junior programmer to develop his application.Using default database.
-
create_database
(path=None)[source]¶ create database
Parameters: path (str) – database path.Warining:It’a a dir Returns: True/False
-
pay_ads
(wallet, claim_id, authername)[source]¶ user view ads
Parameters: - wallet (str) – user wallet name
- claim_id (str) – resource claim id
- authername (str) – resource auther name
Returns: errcode.You can query from the errcode.
-
pay_resources
(payer, claim_id, password, encrypted=False)[source]¶ user pay resource
Parameters: - payer (User) – payer
- claim_id (str) – resource claim id
- password (str) – payer password
Returns: errcode.You can query from the errcode.
-
query
(sql)[source]¶ advanced command self query
Parameters: sql (str) – sql sentence Returns: query result
-
resouce_views
(claim_id)[source]¶ add resource view
Parameters: claim_id (str) – resource claim_id Returns: resource current view
-
resource_publish
(title, udfshash, amount, tags, des, usercondition)[source]¶ user publish resource
Parameters: - title (str) – resource title
- udfshash (str) – resource uplorded to the UDFS hash
- amount (float) – resource price
- tags (list) – resource tag
- des (str) – resource description
- usercondition (dict) – a condition which need to query user
Returns: errcode.You can query from the errcode.
-
resource_update
(id, pay_password, encrypted=True, title=None, body=None, price=None, tags=None, des=None)[source]¶ user update data to the ulord-platform
Parameters: - id (str) – data id
- pay_password (str) – auther wallet pay password
- encrypted (bool) – if encrypt password
- title (str) – resource title
- body (str) – resource
- price (float) – resource price
- tags (list) – resource tags
- des (str) – resource description
Returns: errcode.You can query from the errcode.
-
user_activity
(token=None, username=None)[source]¶ activity.App developer send some ulords to the user.
Parameters: - token (str) – user token
- username (str) – user name
Returns: True or False.
-
user_info_query
(username=None, token=None)[source]¶ user information
Parameters: - username (str) – username.Default is none.
- token (str) – user token.Default is none.
Returns: dict.User info
-
user_infor_modify
(password, username=None, token=None, encrypted=False, cellphone=None, email=None, new_password=None)[source]¶ - user information
Parameters: - username (str) – username.Default is none.
- token (str) – user token.Default is none.
- encrypted (bool) – if encrypted password.If ture,all password will be decrypted.
- password (str) – user passowrd to confirm account
- cellphone (str) – user new cellphone
- email (str) – user new email
- new_password (str) – user new password
Returns: dict.User info
-
user_login
(username, password, encrypted=False)[source]¶ user login
Parameters: - username (str) – user name
- password (str) – user password
- encrypted (bool) – check if the password is encrypted
Returns: user token
-
user_logout
(token=None, username=None)[source]¶ user logout.Change user’s timestamp
Parameters: - token (str) – user token
- username (str) – user name
Returns: username or errcode.You can query the errcode dict.
-
user_regist
(username, password, cellphone=None, email=None, wallet=None, pay_password=None, encrypted=False)[source]¶ user regist
Parameters: - username (str) – user name
- password (str) – user password
- cellphone (str) – user cellphone.Default is None.
- email (str) – user email.Default is None.
- wallet (str) – user wallet name.Default is username.
- pay_password (str) – user wallet password.Default is hash password.
- encrypted (bool) – check if the password encrypted
Returns: user token
-
-
class
ulordapi.user.
Senior
(appkey, secret)[source]¶ Bases:
ulordapi.user.Developer
Senior programmer to develop his application.
utils¶
-
class
ulordapi.utils.
FileHelper
[source]¶ file helper to operate the files
-
changeName
(originalname, newname)[source]¶ change file name from a hash to filename
Parameters: - originalname (str) – a file path, old file name.
- newname (str) – a file path, new file name.
Returns: True or False
-
getName
(filename)[source]¶ get file name,including type
Parameters: filename (str) – a file path Returns: file name
-
getPureName
(filename)[source]¶ get file name.Doesn’t contain type.
Parameters: filename (str) – a file path Returns: file name
-
mergeFile
(filepath, chunks)[source]¶ merge chunks into a file.Used for the multi-threading download
Parameters: - filepath (str) – a file path.Final file.
- chunks (list) – chunk path list
Returns: True or False
-
-
ulordapi.utils.
ListToDict
(args)[source]¶ change a list to dict
Parameters: args (list) – a list Returns: dict >>> a = [1,2,3,4] >>> print(ListToDict(a)) {1: {2: {3: 4}}}
-
class
ulordapi.utils.
RSAHelper
(public_path, private_path)[source]¶ Bases:
object
rsa helper.Create private key and public key.
-
decrypt
(prikey, message)[source]¶ using private key to decrypt message
Parameters: - prikey (Crypto.PublicKey.RSA.RsaKey) – private key
- message (str) – need to be decrypted
Returns: decrypted message
-
-
ulordapi.utils.
Update
(orgin_dict, dict_father)[source]¶ update dict dict_father to dict orgin_dict
Parameters: - orgin_dict (dict) – base dict
- dict_father (dict) – need to update
Returns: dict orgin_dict which updates orgin_dict
In [8]: dictb = { ...: "t":2, ...: "ttt":{ ...: "123":1, ...: "a":2 ...: } ...: ...: } In [9]: dicta = { ...: "test": 1, ...: "ttt":{ ...: "a":1 ...: } ...: } In [10]: Update(dictb, dicta) Out[10]: {'t': 2, 'test': 1, 'ttt': {'123': 1, 'a': 1}}
-
ulordapi.utils.
generateMD5
(value)[source]¶ generate value’s md5
Parameters: value (str) – need to encrypt Returns: value’s md5 or “”
-
ulordapi.utils.
isCellphone
(number)[source]¶ check if a cellphone
Parameters: number (str) – cellphone Returns: True of False
-
ulordapi.utils.
isMail
(mail)[source]¶ check if a mail
Parameters: mail (str) – mail Returns: True of False
-
ulordapi.utils.
isUdfsHash
(udfshash)[source]¶ check the string if a udfs hash simple check, TODO advanced check
Parameters: udfshash (str) – a string Returns: True or False
version¶
webServer¶
-
ulordapi.webServer.
add_views
()[source]¶ add views according to the resource’s title
Returns: current views
-
ulordapi.webServer.
blog_delete
()[source]¶ delete blog :return: errcode.You can query from the errcode dict.
-
ulordapi.webServer.
check_bought
()[source]¶ check the resource if has been bought
Returns: if has bought return resource hash,if not existed return null,if hasn’t bought return none.
About py-ulord-api¶
Ulord is a P2P value delivery public chain. Through building its blockchain underlying architecture and digital resource distribution protocols, it enables third-party developers to explore their own applications over open-source agreements to form a complete ecology of blockchain technology and applications. Based on various rules and protocols created by Ulord, it loads various types of digital resource application scenarios including text, pictures, music, video and software, providing a direct docking platform for information creators and consumers.
This is a toolkit to save your resource to the ulord-platform.