Difference between revisions of "Simple Access API"

From Gramps
Jump to: navigation, search
m
(What is available?: make compatible with python 3 and fix spacing and spaces in example code for clarity)
(12 intermediate revisions by 5 users not shown)
Line 1: Line 1:
As of GRAMPS version 3.0, a database API directed to plugin writers is available, The Simple Access API, accompanied with a Simple Document API for easy presentation of the data.
+
{{man note|As of Gramps version 3.0|a database API directed to plugin writers is available}}
 +
 
 +
The Simple Access API, accompanied with a Simple Document API for easy presentation of the data.
  
 
==Introduction==
 
==Introduction==
Line 7: Line 9:
 
The simplified API hides most of the complexity. Full objects are returned, so you can easily consume a lot of memory with large databases. The routines themselves do not consume a significant amount of memory, but if you decided to keep your own lists or dictionaries of data, you will consume memory quickly.  
 
The simplified API hides most of the complexity. Full objects are returned, so you can easily consume a lot of memory with large databases. The routines themselves do not consume a significant amount of memory, but if you decided to keep your own lists or dictionaries of data, you will consume memory quickly.  
  
This class is specifically constructed for use in the plugins, or to make [[Quick Reports|quick reports]] (available in the context menu's).  
+
This class is specifically constructed for use in the plugins, or to make [[Quick Views|quick views]] (available in the context menu's).
  
 
==What is available?==
 
==What is available?==
  
You can view the API in '''_SimpleAccess.py''' right [http://gramps.svn.sourceforge.net/viewvc/gramps/trunk/src/Simple/_SimpleAccess.py?view=markup here].  
+
You can view the API in [https://github.com/gramps-project/gramps/blob/master/gramps/gen/simple/_simpleaccess.py _simpleaccess.py].  
  
 
Example use:
 
Example use:
from Simple import SimpleAccess
+
<pre>
sdb = SimpleAccess(database)
+
from __future__ import print_function
# grab our current id, so we can filter the active person out
+
 
# of the data
+
from simple import simpleaccess
person = database.active_person()
+
 
gid = sdb.gid(database.active_person())
+
sdb = simpleaccess(database)
# loop through each family in which the person is a child
+
 
for family in sdb.child_in(person):
+
# grab our current id, so we can filter the active person out
  # loop through each child in the family
+
# of the data
  for child in sdb.children(family):
+
person = database.active_person()
      #print something to terminal
+
gid = sdb.gid(database.active_person())
      print sdb.name(child),sdb.gender(child), sdb.birth_date(child))
+
 
 +
# loop through each family in which the person is a child
 +
for family in sdb.child_in(person):
 +
 
 +
    # loop through each child in the family
 +
    for child in sdb.children(family):
 +
 
 +
        #print something to terminal
 +
        print(sdb.name(child),sdb.gender(child), sdb.birth_date(child)))
 +
</pre>
 +
 
 +
==See also==
 +
* [https://gramps-project.org/api_4_2_x/simple.html The Simple Classes] - Gramps API documentation
  
 
[[Category:Developers/General]]
 
[[Category:Developers/General]]
 
[[Category:Developers/Tutorials]]
 
[[Category:Developers/Tutorials]]
[[Category:Reports]]
+
[[Category:Reports|A]]
[[Category:Views]]
+
[[Category:Views|A]]

Revision as of 03:21, 7 April 2018

Gramps-notes.png
As of Gramps version 3.0

a database API directed to plugin writers is available

The Simple Access API, accompanied with a Simple Document API for easy presentation of the data.

Introduction

The normal database routines are optimized for low memory usage, and if used properly, will take up almost no memory. This is key when using large databases. Typically, instead of maintaining dictionaries or lists of objects, we can use the database "handles", and access the data only when explicitly needed. This memory efficiency comes at the cost of being fairly complicated to use.

The simplified API hides most of the complexity. Full objects are returned, so you can easily consume a lot of memory with large databases. The routines themselves do not consume a significant amount of memory, but if you decided to keep your own lists or dictionaries of data, you will consume memory quickly.

This class is specifically constructed for use in the plugins, or to make quick views (available in the context menu's).

What is available?

You can view the API in _simpleaccess.py.

Example use:

from __future__ import print_function

from simple import simpleaccess

sdb = simpleaccess(database)

# grab our current id, so we can filter the active person out
# of the data
person = database.active_person()
gid = sdb.gid(database.active_person())

# loop through each family in which the person is a child
for family in sdb.child_in(person):

    # loop through each child in the family
    for child in sdb.children(family):

        #print something to terminal
        print(sdb.name(child),sdb.gender(child), sdb.birth_date(child)))

See also