pynami package

Submodules

pynami.constants module

This module defines some constants needed for communication with the NaMi.

BASE_URL = 'https://nami.dpsg.de/ica/'

Base URL of the server

Type:str
DEFAULT_PARAMS = {'limit': 10000, 'page': 1, 'start': 0}

Default parameters to avoid pagination. The NaMi uses 5000 as limit when using the show all option.

Type:dict
class URLMetaClass[source]

Bases: type

Meta class for URLS

Makes the class accessible like a dict and prepends the base url when this is done. The relative URL string can be retrieved in the usual way as attributes.

class URLS[source]

Bases: object

Contains all relative REST URLs.

The class attributes can be accessed like a dict in order to get the full URL (prepeding the base URL). The relative URL strings can be retrieved like normal class attributes.

Example

>>> URLS.AUTH
'/nami/auth/manual/sessionStartup'
>>> URLS['AUTH']
'https://nami.dpsg.de/ica/rest/nami/auth/manual/sessionStartup'

This is not just a dict so that each URL can be documented.

Note

Some URL strings have to formatted with some variables.

ALLE_TAETIGKEITEN = '/nami/search-multi/all-visible-taetigkeiten'
AUSBILDUNG = '/nami/mitglied-ausbildung/filtered-for-navigation/mitglied/mitglied/'
AUTH = '/nami/auth/manual/sessionStartup'
BAUSTEIN = '/module/baustein'
BEANTRAGUNG = '/fz-beantragen/download-beantragung'
BEITRAGSART = '/namiBeitrag/beitragsart/gruppierung/{grpId}/'
BEITRAGSART_MGL = '/namiBeitrag/beitragsartmgl/gruppierung/{grpId}/'
EBENE = '/orgadmin/ebene/'
EBENE1 = '/nami/search-multi/ebene/1'
EBENE2 = '/nami/search-multi/ebene/2/gruppierung1/{grpId}/'
EBENE3 = '/nami/search-multi/ebene/3/gruppierung2/{grpId}/'
FZ = '/nami/fz/eigene-bescheinigungen/'
GESCHLECHT = '/baseadmin/geschlecht/'
GETMGL = '/nami/mitglied/filtered-for-navigation/gruppierung/gruppierung/{gruppierung}/{mitglied}'
GET_TAG = '/nami/mitglied-tagged-item/filtered-for-navigation/identitaet/identitaet/{mglId}/{tagId}'
GRPADMIN_GRPS = '/nami/gruppierungen-for-grpadmin/parentgruppierung/node/root'
GRUPPIERUNGEN = '/nami/gruppierungen/filtered-for-navigation/gruppierung/node/root'
HISTORY = '/dashboard/history-entries/flist'
INVOICE = '/nami/rechin-for-grpadmin/rechin/gruppierung/'
INVOICE_PDF = '/nami/rechin-for-grpadmin/pdf'
KONFESSION = '/baseadmin/konfession/'
LAND = '/baseadmin/land/'
LOGOUT = '/nami/auth/logout'
MGLTYPE = '/nami/enum/mgltype'
MGL_HISTORY = '/nami/mitglied-history/filtered-for-navigation/mitglied/mitglied/'
MGL_HISTORY_EXT = '/nami/mitglied-history-with-values/filtered-for-navigation/mitglied/mitglied/'
MGL_TAETIGKEITEN = '/nami/zugeordnete-taetigkeiten/filtered-for-navigation/gruppierung-mitglied/mitglied/'
NOTIFICATIONS = '/dashboard/notification-entries/flist'
REGION = '/baseadmin/region/'
SEARCH = '/nami/search-multi/result-list'
SEARCH_ALL = '/nami/mitglied/filtered-for-navigation/gruppierung/gruppierung/{gruppierung}/flist'
SERVER = ''
STAAT = '/baseadmin/staatsangehoerigkeit/'
STATS = '/dashboard/stats/stats'
STATUS_LIST = '/nami/search-multi/status-list'
STUFENWECHSEL = '/mgl-verwaltungS/stufenwechsel'
TAGLIST = '//tagging/getTagList'
TAGS = '/nami/mitglied-tagged-item/filtered-for-navigation/identitaet/identitaet/{mglId}/flist'
TK_AUF_GRP = '//nami/taetigkeitaufgruppierung/filtered/gruppierung/gruppierung/{grpId}/'
TK_CAEA_GRP = '//nami/caea-group/filtered-for-navigation/taetigkeit/taetigkeit/{taetigkeitId}/'
TK_GRP = '//nami/gf/gruppierung'
TK_UG = '//nami/untergliederungauftaetigkeit/filtered/untergliederung/taetigkeit/{taetigkeitId}/'
UNTERGLIEDERUNG = '/orgadmin/untergliederung'
ZAHLUNGSKONDITION = '/baseadmin/zahlungskondition/'
class UgId[source]

Bases: enum.Enum

Untergliederungs ID

JUFFI = 2
PFADI = 3
ROVER = 4
STAVO = 5
WOE = 1

pynami.nami module

NAMI library in python

This module contains the main class NaMi and a few simple exception definitions.

class NaMi(config={}, **kwargs)[source]

Bases: object

Main class for communication with the DPSG NaMi

Example

Connect to the NaMi, search for all active members and print them in a tabulated form.
from pynami.nami import NaMi
from pynami.tools import tabulate2x

with NaMi(username='MITGLIEDSNUMMER', password='PASSWORD') as nami:
    print(tabulate2x(nami.search()))
Parameters:config (dict, optional) – Authorization configuration
_check_response(response)[source]

Check a requests response object if the NaMi response looks ok. This currently checks some very basic things.

Raises:
_get_baseadmin(key, grpId=None, mglId=None, taetigkeitId=None, **kwargs)[source]

Base function for retrieving all core lists from the NaMi

Parameters:
  • key (str) – Name of the wanted items
  • grpId (int or str, optional) – Group id
  • mglId (int or str, optional) – Member id (not the DPSG Mitgliedsnummer)
  • taetigkeitId (int, optional) – Id of an activity. A list of all possible ids can be found in the section Activity types. This is only required for the URLs which needs to be formatted with this value.
Keyword Arguments:
 
  • gruppierung (int or str, optional) – Group id, in case this differs from the group id in the URL (given by grpId)
  • mitglied (int or str, optional) – Member id (not the DPSG Mitgliedsnummer). This overwrites mglId.
Returns:

The returned default values

Return type:

list of Baseadmin

activities

Functional activities

Type:list of Baseadmin
auth(username=None, password=None)[source]

Authenticate against the NaMi API. This stores the jsessionId cookie in the requests session. Therefore this needs to be called only once.

This also stores your id (not the Mitgliednummer) for later pruposes.

Parameters:
  • username (str, optional) – The NaMi username. Which is your Mitgliedsnummer
  • password (str, optional) – Your NAMI password
Returns:

The requests session, including the auth cookie

Return type:

requests.Session

bausteine

Choose DPSG training parts

Type:list of Baseadmin
beitragsarten(grpId=None, mglId=None)[source]

Get default values

Parameters:
  • grpId (int or str, optional) – Group id
  • mglId (int or str, optional) – Member id (not the DPSG Mitgliedsnummer)
Returns:

Each possible fee type

Return type:

list of Baseadmin

beitragsarten_mgl(grpId=None, mglId=None)[source]

Get default values

Parameters:
  • grpId (int or str, optional) – Group id
  • mglId (int or str, optional) – Member id (not the DPSG Mitgliedsnummer)
Returns:

Each possible fee for a member

Return type:

list of Baseadmin

bescheinigungen(**kwargs)[source]

Get all certificates of inspection

Returns:A list of all your certificates of inspection
Return type:list of SearchBescheinigung
countries(grpId=None, mglId=None)[source]

Get default values

Parameters:
  • grpId (int or str, optional) – Group id
  • mglId (int or str, optional) – Member id (not the DPSG Mitgliedsnummer)
Returns:

List of all possible countries with their names and ids

Return type:

list of Baseadmin

download_beantragung(**kwargs)[source]

Open the application form for a certificate of good conduct as a PDF file.

Parameters:**kwargs – See open_download_pdf().
download_bescheinigung(id_, **kwargs)[source]

Open a certificate as a PDF file

Parameters:
download_invoice(id_, **kwargs)[source]

Downloads and opens an invoice as a pdf document.

Parameters:
ebene1

You can choose a Diözese which you belong to.

Type:list of Baseadmin
ebene2(ebene1)[source]

You can choose a Bezirk which you belong to.

Parameters:ebene1 (int) – Group id of a Diözese
Returns:List of possible Bezirken you are associated with
Return type:list of Baseadmin
ebene3(ebene2)[source]

You can choose a Stamm which you belong to.

Parameters:ebene2 (int) – Group id of a Bezirk
Returns:List of possible Stämmen you are associated with
Return type:list of Baseadmin
ebenen

Structural layersin the DPSG

Type:list of Baseadmin
geschlechter(grpId=None, mglId=None)[source]

Get default values

Parameters:
  • grpId (int or str, optional) – Group id
  • mglId (int or str, optional) – Member id (not the DPSG Mitgliedsnummer)
Returns:

You can choose between three genders: male, female and diverse.

Return type:

list of Baseadmin

get_activity(mgl, id_)[source]

Get an activity by its id.

Parameters:
  • mgl (int) – Member id (not DPSG Mitgliedsnummer)
  • id (int) – Id of the activity. This will probably originate from an activity search result, e.g. by calling mgl_activities().
Returns:

The Activity object containing all details.

Return type:

Activity

get_ausbildung(mglId, id_)[source]

Get a training by its id.

Parameters:
  • mglId (int) – Member id (not DPSG Mitgliedsnummer)
  • id (int) – Id of the training. This will probably originate from an training search result, e.g. by calling mgl_ausbildungen().
Returns:

The Ausbildung object containing all details about the training.

Return type:

Ausbildung

get_bescheinigung(id_)[source]

View a certificate of inspection by its id

Parameters:id (int) – The internal id of the certificate
Returns:An object holding all important details about the inspection
Return type:Bescheinigung
get_mgl_history(mglId, id_, ext=True)[source]

Get a member history entry by its id.

Parameters:
  • mglId (int) – Member id (not DPSG Mitgliedsnummer)
  • id (int) – Id of the entry. May originate from a search result, e.g. by calling mgl_history().
  • ext (bool, optional) – If the extended history format should be used. Defaults to True.
Returns:

The object containing all vital information about this history entry.

Return type:

MitgliedHistory

get_tag(mglId, tagId)[source]

Get a tag by its id

Parameters:
  • mglId (int) – Member id (not DPSG Mitgliedsnummer)
  • tagId (int) – Tag id
Returns:

The tag object with all important details

Return type:

Tag

grpId

Group id of the user

Returns:int
grpadmin_grps

Choose from a list of groups that you are associated with for group admin

Type:list of Baseadmin
gruppierungen

Choose from a list of groups that you are associated with for member admin

Type:list of Baseadmin
history(**kwargs)[source]

Dashboard function

Returns:Last editing events like updating and creating members.In the NaMi these are displayed in the dashboard.
Return type:list of HistoryEntry
invoice(groupId, invId)[source]

Get an invoice by its id.

Parameters:
  • groupId (int) – Group id
  • invId (int) – Id of the invoice. This will probably originate from a search result, e.g. by calling invoices().
Returns:

The Invoice object containing all details.

Return type:

Invoice

invoices(groupId=None, **kwargs)[source]

List of all invoices of a group

Parameters:groupId (int, optional) – Group id
Returns:All invoices of the specified group
Return type:list of SearchInvoice
konfessionen(grpId=None, mglId=None)[source]

Get default values

Parameters:
  • grpId (int or str, optional) – Group id
  • mglId (int or str, optional) – Member id (not the DPSG Mitgliedsnummer)
Returns:

All denominations

Return type:

list of Baseadmin

logout()[source]

This should be called at the end of the communication. It is called when exiting through the __exit__() method.

mgl_activities(mgl)[source]

List of all activities of a member

Parameters:mgl (int) – Member id (not DPSG Mitgliedsnummer)
Returns:All activities of the member (even those which have already ended)
Return type:list of Activity
mgl_ausbildungen(mglId)[source]

Get all trainings from a Mitglied.

Parameters:mglId (int) – Member id (not DPSG Mitgliedsnummer)
Returns:All trainings of the member
Return type:list of SearchAusbildung
mgl_history(mglId, ext=True)[source]

Get all history changes from a Mitglied.

Parameters:
  • mglId (int) – Member id (not DPSG Mitgliedsnummer)
  • ext (bool, optional) – If the extended history format should be used. Defaults to True.
Returns:

All history entries of the member

Return type:

list of HistoryEntry

mgltypes(grpId=None, mglId=None)[source]

Get default values

Parameters:
  • grpId (int or str, optional) – Group id
  • mglId (int or str, optional) – Member id (not the DPSG Mitgliedsnummer)
Returns:

You can have one of three different member types

Return type:

list of Baseadmin

mitglied(mglId=None, method='GET', grpId=None, **kwargs)[source]

Gets or updates a Mitglied.

The keyword arguments are passed on to the HTTP communication

Parameters:
  • mglId (int, optional) – ID of the Mitglied. This is not the DPSG Mitgliedsnummer. Defaults to the user.
  • method (str) – HTTP Method. Should be 'GET' or 'PUT', defaults to 'GET'.
  • grpId (int, optional) – The DPSG Stammesnummer, e.g. 131913. The default (None) takes the value from the internal attribute __config.
Returns:

The retrieved or respectively updated Mitglied. Note that the austrittsDatum attribute is not part of the returned data set.

Return type:

Mitglied

myId

NaMi internal id of the user

Returns:int
notifications(sortproperty=None, sortdirection='ASC', **kwargs)[source]

Dashboard function

Returns:All current notifications (like tier changes of members). In the NaMi these are displayed in the dashboard.
Return type:list of Notification
regionen(grpId=None, mglId=None)[source]

Get default values

Parameters:
  • grpId (int or str, optional) – Group id
  • mglId (int or str, optional) – Member id (not the DPSG Mitgliedsnummer)
Returns:

All possible Bundeslaender

Return type:

list of Baseadmin

search(**kwargs)[source]

Run a search for members

Todo

  • Check search terms and formatting. Also some search keys can only be used mutually exclusive.
Parameters:**kwargs – Search keys and words. Be advised that some search words must have a certain formatting or can only take a limited amount of values.
Returns:The search results
Return type:list of SearchMitglied

See also

SearchSchema for a complete list of search keys

search_all(grpId=None, filterString=None, searchString='', sortproperty=None, sortdirection='ASC', **kwargs)[source]

Search function for filtering the whole member list with limited filter options.

It is also possible to sort the results.

Parameters:
  • filterString (str, optional) – Filter attribute.
  • searchString (str, optional) – You can search within the chosen filter attribute. The Format must match the type of the filter attribute.
  • sortproperty (str, optional) – Attribute by wich the results shall be sorted.
  • sortdirection (str, optional) – Direction of sorting. Can take the values ASC (wich is the default) and DESC.
Returns:

The search results

Return type:

list of SearchMitglied

staaten(grpId=None, mglId=None)[source]

Get default values

Parameters:
  • grpId (int or str, optional) – Group id
  • mglId (int or str, optional) – Member id (not the DPSG Mitgliedsnummer)
Returns:

A quite long list of different nationalities

Return type:

list of Baseadmin

stats

Contains counts from different tiers. The actual list of StatCategory is in the statsCategories attribute.

Type:Stats
status_list

If you are active, inactiv or already deleted

Type:list of Baseadmin
subdivision

Which division you are associated with. This one is only used for searching.

Type:list of Baseadmin
tagList

A different list of fee types but with basically the same content. This one is used for searching members.

Deprecated since version 0.3.3: Only returns an empty list and has therefore become useless.

Type:list of Baseadmin
tags(mglId, **kwargs)[source]

Get all tags of a member

Parameters:mglId (int) – Member id (not DPSG Mitgliedsnummer)
Returns:List of the search results
Return type:list of SearchTag
tk_auf_grp(grpId, mglId, **kwargs)[source]

Get all possible activities for a certain group

Parameters:
  • grpId (int or str) – Group id
  • mglId (int or str) – Member id (not the DPSG Mitgliedsnummer)
Returns:

List of possible activities

Return type:

list of Baseadmin

tk_caea_grp(grpId, mglId, taetigkeitId, **kwargs)[source]

Get all possible access rights for an activity

Parameters:
  • grpId (int or str) – Group id
  • mglId (int or str) – Member id (not the DPSG Mitgliedsnummer)
  • taetigkeitId (int) – Id of the activity. A list of all possible ids can be found in the section Activity types.
Returns:

List of possible access rights

Return type:

list of Baseadmin

tk_grp(grpId, mglId, **kwargs)[source]

Get all possible groups for an activity

Parameters:
  • grpId (int or str) – Group id
  • mglId (int or str) – Member id (not the DPSG Mitgliedsnummer)
Returns:

List of possible groups

Return type:

list of Baseadmin

tk_ug(grpId, mglId, taetigkeitId, **kwargs)[source]

Get all possible subdivision for an activity

Parameters:
  • grpId (int or str) – Group id
  • mglId (int or str) – Member id (not the DPSG Mitgliedsnummer)
  • taetigkeitId (int) – Id of the activity. A list of all possible ids can be found in the section Activity types.
Returns:

List of possible subdivision

Return type:

list of Baseadmin

update_activity(mgl, act)[source]

Update an activity

Parameters:
  • mgl (int) – Member id (not DPSG Mitgliedsnummer)
  • act (Activity) – Updated data set. The activity id is taken form this data set.
Returns:

A new updated object

Return type:

Activity

Warning

This has not been tested yet!

update_ausbildung(mglId, ausbildung)[source]

Update a training

Parameters:
  • mgl (int) – Member id (not DPSG Mitgliedsnummer)
  • ausbildung (Ausbildung) – Updated data set. The training id is taken form this data set.
Returns:

A new updated object

Return type:

Ausbildung

Warning

This has not been tested yet!

zahlungskonditionen(grpId=None, mglId=None)[source]

Get default values

Parameters:
  • grpId (int or str, optional) – Group id
  • mglId (int or str, optional) – Member id (not the DPSG Mitgliedsnummer)
Returns:

Every paying method (either bank transfer or debit)

Return type:

list of Baseadmin

exception NamiHTTPError[source]

Bases: Exception

Raised when the HTTP status code was not as expected!

exception NamiResponseSuccessError[source]

Bases: Exception

This is being raised when the response ‘success’ field is not True.

exception NamiResponseTypeError[source]

Bases: Exception

This is raised when the response type from the NaMi is not in list of allowed values or more specifically when the NaMi returns an error, a warning or an exception.

pynami.util module

Some utility functions that are used by other classes and methods from this # package but not directly connected to the NaMi.

class ExtractHrefParser(*, convert_charrefs=True)[source]

Bases: html.parser.HTMLParser

HTML parser for extracting a URL

handle_starttag(tag, attrs)[source]

Handles a HTML tag

Parameters:
  • tag (str) – The HTML tag
  • attrs (list) – Attributes inside the tag as name and value tuples
url = None

URL embedded in HTML tags

Type:str
extract_url(htmlstr)[source]

Extract a URL from a HTML string.

Parameters:htmlstr (str) – The HTML string which will be parsed.
Returns:The URL
Return type:str
open_download_pdf(content, open_file=True, save_file=False, timeout=10, filename='')[source]

Open and/or save a downloaded PDF file.

When you only want to open the file: To avoid having to deal with graphical save-the-file dialogues a temporary file inside a temporary directory is created which is deleted after a timeout that is used to open the file. During this timeout the program is blocked.

Parameters:
  • content (bytes) – Content of the downloaded file
  • open_file (bool, optional) – Wether to directly open the downloaded file. Defaults to True.
  • save_file (bool, optional) – Wether to save the downloaded file to disc. Defaults to False.
  • timeout (float, optional) – Time the system has for opening the file. Defaults to 10 seconds.
  • filename (str, optional) – Full path to save file
validate_iban(value)[source]

Validate an IBAN

Parameters:value (str) – Value to check. Spaces are allowed.
Raises:ValidationError – In case of invalid IBAN.
Returns:The IBAN in compact form.
Return type:str

pynami.tools module

Some utility functions for user convenience

export_xlsx(data, attrs=None, includeheader=True, tableName='Tabelle1', sheetName='Data', write_to_file=False, filepath='')[source]

Create a Microsoft Excel Wokbook from a given dataset. The data can optionally be saved to a file.

Parameters:
  • data (list) – Data objects. They should all belong to the same class.
  • attrs (list of str, optional) – Attribute names for the CSV table. If left empty (None) the value of the first _tabkeys attribute in the list is taken.
  • includeheader (bool, optional) – Whether to include headers in the output. Defaults to True.
  • tableName (str, optional) – Name of the table. Defaults to ‘Tabelle1’.
  • sheetName (str, optional) – Name of the worksheet. Defaults to ‘Data’.
  • write_to_file (bool, optional) – If the workbook should be saved to a file. Defaults to False.
  • filepath (str, optional) – Full path to the Excel file where the data should be saved. If left empty the default savefile dialog will be invoked via the module tkinter.
Returns:

The created workbook.

Return type:

Workbook

make_csv(data, attrs=None, includeheader=True, delimiter=', ')[source]

Makes a CSV formatted string from a data set

Parameters:
  • data (list) – Data objects. They should all belong to the same class.
  • attrs (list of str, optional) – Attribute names for the CSV table. If left empty (None) the value of the first _tabkeys attribute in the list is taken.
  • includeheader (bool, optional) – Whether to include headers in the output. Defaults to True.
Returns:

CSV formatted data

Return type:

str

send_emails(mitglieder, to='', method='bcc', email1=True, email2=True, open_browser=True)[source]

Send emails to several members.

Parameters:
  • mitglieder (list) – The List contents can be either SearchMitglied or Mitglied
  • to (str, optional) – Primary recipient
  • method (str, optional) – If you want to send your mails as bcc or something else. Currently only bcc is supported.
  • email1 (bool, optional) – If emails should be send to the primary address of the members.
  • email2 (bool, optional) – If emails should be send to the email account of the member’s parent.
  • open_browser (bool, optional) – If True the link is opened directly by the system. On a computer this may open your default mail program.
Returns:

The mailto link

Return type:

str

tabulate2x(objs, elements=None)[source]

Tabulate a list of objects by tabulating each object first

Parameters:
  • obj (list) – The list of objects to tabulate. If they are not from the same class this may not work.
  • elements (list of str, optional) – List of keys which should be displayed
Returns:

Nicely formatted tabulated output

Return type:

str