bulkdata¶
Subpackages¶
Submodules¶
bulkdata.card¶
The card
module provides classes related
to the creation and manipulation of bulk data card objects.
It contains the Card
class that
facilitates the conversion of collections of field values to
and from bulk data card formatted strings.
-
class
bulkdata.card.
Card
(name=None, size=0)[source]¶ Card
class allows the user to create and modify bulk data cards.Parameters: - name – The name of the card
- size – The number of initial blank fields, defaults to 0
-
__delitem__
(key)[source]¶ Delete the field item from card.
Parameters: key (int, slice) – The indexing key denoting which field(s) to delete
-
__getitem__
(key)[source]¶ Get field item from the card.
Parameters: key (int, slice, list) – The indexing key denoting which field(s) to get Returns: The field value(s)
-
__setitem__
(key, value)[source]¶ Set field item into the card.
Parameters: - key (int, slice, list) – The indexing key denoting where to set the field(s)
- value – The field value(s) to set
-
__str__
()[source]¶ Dump the card to as a bulk data card string with default format.
Returns: The bulk data card string
-
append
(value, fieldspan=1)[source]¶ Append a field value to card fields.
Parameters: - value – The field value
- fieldspan – The number of field cells the value spans, defaults to 1
-
dumps
(format='fixed')[source]¶ Dump the card to bulk data formatted string.
Parameters: format – the desired format, can be one of: [“free”, “fixed”], defaults to “fixed” Returns: The bulk data card string representation
-
extend
(values, fieldspan=1)[source]¶ Extend card fields with sequence of field values.
Parameters: - values – The sequence of field values
- fieldspan – The number of field cells that each value spans, defaults to 1
-
fields
¶ The card fields.
-
get_large
(key)[source]¶ Get field value spanning multiple fields. This gets the same fields as
__getitem__()
but it joins them before converting to a single large value.Parameters: key – The indexing object denoting which field(s) to get Returns: The large field value
-
classmethod
loads
(card_str)[source]¶ Load
Card
object from a bulk data card string.Parameters: card_str – the bulk data card string Returns: The loaded Card
object
-
name
¶ The card name.
-
resize
(size)[source]¶ Resize the card fields to contain size fields. If current number of fields is greater than size, the extra fields will be removed from the end. If number of fields is less than size, extra blank fields are appended.
Parameters: size – The desired number of fields
bulkdata.cli¶
Console script for bulkdata. (Currently does nothing)
bulkdata.deck¶
The deck
module provides the
Deck
class.
-
class
bulkdata.deck.
Deck
(cards=None, header=None)[source]¶ Deck
class allows the user to load and update bulk data files, loading the bulk data cards intoCard
objects.Parameters: - cards – initialize the deck with these cards,
defaults to
None
. - header – the header, which is prepended to the bulk
data section when dumping the deck,
defaults to
None
.
-
__getitem__
(key)[source]¶ Get card(s) in the deck.
Parameters: key (int, slice, list, str) – The indexing key denoting where to get the card(s) Returns: The card(s) If key is of type
str
, this method returns all cards with name key.
-
__setitem__
(key, value)[source]¶ Set card(s) in the deck.
Parameters: - key (int, slice, list) – The indexing key denoting where to set the card(s)
- value – The card(s) to set
-
__str__
()[source]¶ Dump the deck to as a bulk data string with default format
Returns: The bulk data string
-
cards
¶ The deck cards.
-
delete
(filter=None)[source]¶ Delete cards matching the query denoted by filter.
Parameters: filter (dict, str) – Specifies which cards to delete. Returns: The number of cards deleted.
-
dump
(fp, format='fixed')[source]¶ Dump the deck to a bulk data file.
Parameters: - fp – The bulk data file object
- format – The desired format, can be one of: [“free”, “fixed”], defaults to “fixed”
-
dumps
(format='fixed')[source]¶ Dump the deck to a bulk data string.
Parameters: format – The desired format, can be one of: [“free”, “fixed”], defaults to “fixed” Returns: The bulk data string
-
extend
(cards)[source]¶ Extend deck cards with sequence of cards.
Parameters: cards – The sequence of cards
-
find
(filter=None)[source]¶ Find cards matching the query denoted by filter.
Parameters: filter (dict, str) – Specifies which cards to find. Returns: A generator object iterating through every card matching the filter. If filter is a
dict
, there are three keywords that may be used.- name,
str
: Filter for cards with matching name. - fields,
dict
: Given an “index” and “field” member, filter cards where the field(s) at index index, has/have value field. - contains: Filter for cards containing a field that matches the contains value, or any contains value if contains is a list.
The following code block is an example of using
find
with a filter dict:filter_ = { # name is ASET1 "name": "ASET1", "fields": { # first field "index": 0, # with value 3 "value": 3 }, # contains values 1 and "THRU" "contains": [1, "THRU"] } card = next(deck.find(filter_)) print(card)
ASET1 3 1 THRU 8
If filter is a
str
, the filter will match cards with name matching filter.card = next(deck.find("AERO")) print(card)
AERO 3 1.3 100. .00001 1 -1
- name,
-
find_one
(filter=None)[source]¶ Find the first card matching the query denoted by filter.
Parameters: filter (dict, str) – Specifies which card to find. Returns: The first matching card, or None
if no match is found.
-
classmethod
load
(fp)[source]¶ Load
Deck
object from a bulk data file object.Parameters: fp – The bulk data file object Returns: The loaded Deck
object
-
classmethod
loads
(deck_str)[source]¶ Load
Deck
object from a bulk data string.Parameters: deck_str – The bulk data string Returns: The loaded Deck
object
-
replace
(filter, card)[source]¶ Replace cards matching the query denoted by filter with card.
Parameters: - filter (dict, str) – Specifies which cards to replace.
- card – The replacement card
-
replace_one
(filter, card)[source]¶ Replace the first card matching the query denoted by filter with card.
Parameters: - filter (dict, str) – Specifies which card to replace.
- card – The replacement card
Returns: The replacement card, or
None
if no match is found.
-
sorted
(key=None, reverse=False)[source]¶ Return a deck containing the sorted deck cards.
Parameters: - key – Specifies a function of one argument that is used to extract a comparison key from each card. If None, the cards will be sorted by name.
- reverse – Boolean value. If set to True, then the cards are sorted as if each comparison were reversed.
Returns: The
Deck
object containing the sorted cards.
-
update
(filter, update)[source]¶ Update cards matching the query denoted by filter with changes denoted by update dict, which has the same keyword options as the fields dict in filter.
Note
Avoid this function as there is no current tutorial, has not been well tested, and does not appear to add any functionality not achieved otherwise.
Parameters: - filter (dict, str) – Specifies which cards to replace.
- card – The replacement card
- cards – initialize the deck with these cards,
defaults to