Difference between revisions of "Simple Access API"

From Gramps
Jump to: navigation, search
(See also)
(11 intermediate revisions by the same user not shown)
Line 1: Line 1:
{{man note|As of Gramps version 3.0|a database API directed to plugin writers is available}}
+
{{man note|The {{man label|Simple Access API}} was introduced in Gramps version 3.0.x|It is a database API([https://en.wikipedia.org/wiki/Application_programming_interface Application programming interface]) made for Gramps plugin/addon writers}}
 
 
The Simple Access API, accompanied with a Simple Document API for easy presentation of the data.
 
  
 +
The Simple Access API, accompanied by the [[Report_API|Simple Document API interface]] for easy presentation of the data have been constructed, so as to hide as much complexity as possible.
 +
__TOC__
 
==Introduction==
 
==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 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 "[https://en.wikipedia.org/wiki/Handle_(computing) 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.  
 
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|quick views]] (available in the context menu's).
+
These Simple Classes are specifically constructed for use in plugins/addons, or to make [[Quick Views]] (available in the context menu's).
  
 
==What is available?==
 
==What is available?==
  
 
You can view the API in [https://github.com/gramps-project/gramps/blob/master/gramps/gen/simple/_simpleaccess.py _simpleaccess.py].  
 
You can view the API in [https://github.com/gramps-project/gramps/blob/master/gramps/gen/simple/_simpleaccess.py _simpleaccess.py].  
 +
 +
{{stub}}<!-- expand to talk about the simple api code and update example for gramps 5.1.x -->
  
 
Example use:
 
Example use:
Line 40: Line 42:
 
==See also==
 
==See also==
 
* [https://gramps-project.org/docs/simple.html The Simple Classes] - Gramps API documentation
 
* [https://gramps-project.org/docs/simple.html The Simple Classes] - Gramps API documentation
 +
* [[Report_API|Simple Document API interface]] for easy presentation of the data.
 +
* [[Quick Views]]
 +
* [[Gramps_5.1_Wiki_Manual_-_Reports_-_part_8#Making_your_own_Quick_view]]
 +
* [[Writing a plugin]]
 +
* [[Report-writing tutorial]]
  
 
[[Category:Developers/General]]
 
[[Category:Developers/General]]

Revision as of 00:38, 28 April 2020

Gramps-notes.png
The Simple Access API was introduced in Gramps version 3.0.x

It is a database API(Application programming interface) made for Gramps plugin/addon writers

The Simple Access API, accompanied by the Simple Document API interface for easy presentation of the data have been constructed, so as to hide as much complexity as possible.

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.

These Simple Classes are specifically constructed for use in plugins/addons, or to make Quick Views (available in the context menu's).

What is available?

You can view the API in _simpleaccess.py.

Gramps-notes.png

This article's content is incomplete or a placeholder stub.
Please update or expand this section.


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