Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
P
ParsePy
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
OpenEdx
ParsePy
Commits
a7bf6886
Commit
a7bf6886
authored
Mar 10, 2013
by
Raphael Lullis
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Updating README for latest changes in code
parent
97ffeb49
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
86 additions
and
48 deletions
+86
-48
README.mkd
+86
-48
No files found.
README.mkd
View file @
a7bf6886
...
@@ -2,37 +2,35 @@ parse_rest
...
@@ -2,37 +2,35 @@ parse_rest
==========
==========
**parse_rest**
is a Python client for the
[
Parse REST
**parse_rest**
is a Python client for the
[
Parse REST
API](https://www.parse.com/docs/rest). It provides Python object
API](https://www.parse.com/docs/rest). It provides:
mapping for Parse objects with methods to save, update, and delete
objects, as well as an interface for querying stored objects.
Installation
-
Python object mapping for Parse objects with methods to save,
------------
update, and delete objects, as well as an interface for querying
stored objects.
-
Complex data types provided by Parse with no python equivalent
-
User authentication, account creation
**
(signup) and querying.
-
Cloud code integration
-
**PLANNED/TODO**
: Installation querying
**
-
**PLANNED/TODO**
: push/channel querying
**
-
**PLANNED/TODO**
: Roles/ACLs
**
-
**PLANNED/TODO**
: Image/File type support
The easiest way to install this package is from
[
PyPI
](
http://pypi.python.org/pypi
)
, either using
[
easy_install
](
http://packages.python.org/distribute/easy_install.html
)
:
easy_install parse_rest
**
for applications with access to the MASTER KEY, see details below.
or
[
pip
](
http://pypi.python.org/pypi/pip
)
:
pip install parse_rest
Installation
------------
(if you are using a Mac or Linux system you may need to prepend
`sudo`
to either command).
Alternatively, you can install it from source
by downloading or
The easiest way to install this package is
by downloading or
cloning this repository:
cloning this repository:
git clone git@github.com:dgrtwo/ParsePy.git
pip install git+git clone git@github.com:dgrtwo/ParsePy.git
and performing the commands:
python setup.py build
Note: The version on
[
PyPI
](
http://pypi.python.org/pypi
)
is not
python setup.py install
up-to-date. The code is still under lots of changes and the stability
of the library API - though improving - is not guaranteed. Please
(again you may have to add
`sudo`
before
`python setup.py install`
)
.
file any issues that you may find if documentation/application
.
Testing
Testing
-------
-------
...
@@ -48,37 +46,82 @@ REST_API_KEY = "REST_API_KEY_HERE"
...
@@ -48,37 +46,82 @@ REST_API_KEY = "REST_API_KEY_HERE"
MASTER_KEY = "MASTER_KEY_HERE"
MASTER_KEY = "MASTER_KEY_HERE"
~~~
~~
~~~
~~
*
install the
[
Parse CloudCode command line
*
install the
[
Parse CloudCode tool
](
https://www.parse.com/docs/cloud_code_guide
)
tool](https://www.parse.com/docs/cloud_code_guide)
You can then test the installation by running:
You can then test the installation by running:
python setup.py test
python setup.py test
Basic
Usage
Usage
-----------
-----------
Let's get everything set up first. You'll need to give
`parse_rest`
Before the first interaction with the Parse server, you need to
your Application Id and REST API Key (available from your Parse
register your access credentials. You can do so by calling
dashboard) in order to get access to your data. All calls to Parse are
`parse_rest.connection.register`
.
done through ParseBase classes, so we need to register the credentials
with it.
Before getting to code, a word of caution. You need to consider how your application is
meant to be deployed. Parse identifies your application though
different keys (available from your Parse dashboard) that are used in
every request done to their servers.
If your application is supposed to be distributed to third parties
(such as a desktop program to be installed), you SHOULD NOT put the
master key in your code. If your application is meant to be running in
systems that you fully control (e.g, a web app that needs to integrate
with Parse to provide functionality to your client), you may also add
your
*master key*
.
~~~
~~ {python}
~~~
~~ {python}
import parse_rest
from parse_rest.connection import register
parse_rest.ParseBase.register(<application_id>, <rest_api_key>
)
register(<application_id>, <rest_api_key>[, master_key=None]
)
~~~
~~
~~~
~~
To create a new object of the Parse class
`GameScore`
, you first
Once your application calls register, you will be able to read, write
create such a class inheriting
`parse_rest.Object`
:
and query for data at Parse.
Data types
----------
Parse allows us to get data in different base types that have a direct
python equivalent (strings, integers, floats, dicts, lists) as well as
some more complex ones (e.g.:
`File`
,
`Image`
,
`Date`
). It also allows
us to define objects with schema-free structure, and save them, as
well to query them later by their attributes.
`parse_rest`
is
handy as a way to serialize/deserialize these objects transparently.
The Object type
---------------
In theory, you are able to simply instantiate a
`Object`
and do
everything that you want with it, save it on Parse, retrieve it later,
etc.
~~~
~~ {python}
from parse_rest.datatypes import Object
first_object = Object()
~~~
~~
In practice, you will probably want different classes for your
application to allow for a better organization in your own code.
So, let's say you want to make an online game, and you want to save the scoreboard on Parse.
For that, you decide to define a class called
`GameScore`
. All you
need to do to create such a class is to define a Python class that
inherts from
`parse_rest.datatypes.Object`
:
~~~
~~ {python}
~~~
~~ {python}
class GameScore(parse_rest.Object):
from parse_rest.datatypes import Object
class GameScore(Object):
pass
pass
~~~
~~
~~~
~~
And then in
itializ
e it with your parameters:
And then in
stantiat
e it with your parameters:
~~~
~~ {python}
~~~
~~ {python}
gameScore = GameScore(score=1337, player_name='John Doe', cheat_mode=False)
gameScore = GameScore(score=1337, player_name='John Doe', cheat_mode=False)
...
@@ -91,10 +134,6 @@ gameScore.cheat_mode = True
...
@@ -91,10 +134,6 @@ gameScore.cheat_mode = True
gameScore.level = 20
gameScore.level = 20
~~~
~
~~~
~
Supported data types are any type that can be serialized by JSON and
Python's _datetime.datetime_ object. (Binary data and references to
other _Object_'s are also supported, as we'll see in a minute.)
To save our new object, just call the save() method:
To save our new object, just call the save() method:
~~~
~~ {python}
~~~
~~ {python}
...
@@ -141,20 +180,19 @@ gameScore.updatedAt
...
@@ -141,20 +180,19 @@ gameScore.updatedAt
Additional Datatypes
Additional Datatypes
--------------------
--------------------
If we want to store binary streams in a Object, we can use the parse_rest.Binary type:
We've mentioned that Parse supports more complex types, most of these
types are also supported on Python (dates, files). So these types can
~~~
~~ {python}
be converted transparently when you use them. For the types that Parse
gameScore.victoryImage = parse_rest.Binary('\x03\xf3\r\n\xc7\x81\x7fNc ... ')
provided and Python does not support natively,
`parse_rest`
provides
~~~
~~
the appropiates classes to work with them. One such example is
`GeoPoint`
, where you store latitude and longitude
We can also store geoPoint dataTypes, with latitude and longitude
as float values.
~~~
~~ {python}
~~~
~~ {python}
class Restaurant(parse_rest.Object):
class Restaurant(parse_rest.Object):
pass
pass
restaurant = Restaurant(name="Los Pollos Hermanos")
restaurant = Restaurant(name="Los Pollos Hermanos")
# coordinates as floats.
restaurant.location = parse_rest.GeoPoint(latitude=12.0, longitude=-34.45)
restaurant.location = parse_rest.GeoPoint(latitude=12.0, longitude=-34.45)
restaurant.save()
restaurant.save()
~~~
~~
~~~
~~
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment