This is a pre-production deployment of Warehouse, however changes made here WILL affect the production instance of PyPI.
Latest Version Dependencies status unknown Test status unknown Test coverage unknown
Project Description

Introduction

PyBBDB may sound like a rude noise, but it is actually a Python interface to the Insidious Big Brother Database (BBDB), an address book used with GNU Emacs. You can find out more about BBDB on the Emacs Wiki. The PyBBDB source repo is hosted at Bitbucket. Releases can be found on PyPI.

Note

This module only handles BBDB version 2. There is a version 3 in development on Savannah, but there has been no public release as yet.

Requirements

To install and run it:
pyparsing, voluptuous and six
To build source distributions from the checked-out Mercurial repo:
hgtools
To run unit tests:
pytest

Installation

The usual incantation will install things:

python setup.py install

Usage

Creating a BBDB database

To create a new database is as simple as you might expect:

>>> from bbdb import BBDB
>>> db = BBDB()

The database starts with no records. To add a new one, use the add_record() method, specifying the first and last names, and any other attributes you want to set:

>>> fred = db.add_record("Fred", "Flintstone")
>>> fred
<Record: Fred Flintstone>

>>> barney = db.add_record("Barney", "Rubble")
>>> db
<BBDB: 2 records>

You can use the returned record object to set other attributes:

>>> fred.set_company("Slate Rock & Gravel")

A Record is a subclass of OrderedDict, so you can set or modify attributes in this style:

>>> fred["company"] = "Slate Rock & Gravel"

As a convenience, there are properties for each of the valid attributes:

>>> fred.firstname
'Fred'

>>> fred.company
'Slate Rock & Gravel'

There’s also a composite name property:

>>> fred.name
'Fred Flintstone'

Some BBDB attributes consist of lists of things, and there are add_*() methods for these:

>>> fred.add_net("fred@bedrock.org")
>>> fred.add_net("fred.flintstone@gravel.com")
>>> fred.net
['fred@bedrock.org', 'fred.flintstone@gravel.com']

>>> fred.add_aka("Freddie")
>>> fred.aka
['Freddie']

Telephone records consist of a location tag and a phone number string:

>>> fred.add_phone("Work", "555-6789")
>>> fred.add_phone("Home", "555-1234")
>>> fred.phone
SortedDict([('Home', '555-1234'), ('Work', '555-6789')])

Records can have multiple addresses, each indexed by a location tag. Each address in turn has several attributes:

>>> home = fred.add_address("Home")
>>> home.add_location("Cave 2a", "345 Cavestone Road")
>>> home.set_city("Bedrock")
>>> home.set_state("Hanna Barbera")
>>> home.set_zipcode("12345")
>>> home.set_country("USA")

>>> home
<Address: Cave 2a, 345 Cavestone Road, Bedrock, Hanna Barbera, 12345, USA>

>>> home.location
['Cave 2a', '345 Cavestone Road']

>>> home.zipcode
'12345'

Finally, each entry can have an arbitrary dictionary of user-defined fields:

>>> fred.add_field("spouse", "Wilma")
>>> fred.add_field("kids", "Pebbles, Bam-Bam")
>>> fred.add_field("catchphrase", '"Yabba dabba doo!"')
>>> fred.fields
SortedDict([('catchphrase', '"Yabba dabba doo!"'), ('kids', 'Pebbles, Bam-Bam'), ('spouse', 'Wilma')])

Reading and writing BBDB files

The write() method will write the database to a stream (default stdout) in a format suitable for use by GNU Emacs:

>>> db.write()                        # doctest: +ELLIPSIS
;; -*-coding: utf-8-emacs;-*-
;;; file-version: 6
;;; user-fields: (catchphrase kids spouse)
["Barney" "Rubble" nil nil nil nil nil nil nil]
["Fred" "Flintstone" ("Freddie") "Slate Rock & Gravel" (["Home" "555-1234"] ...

The convenience write_file() method will put that in a file:

>>> db.write_file("examples/bbdb.el")

You can read a database from file using the fromfile() static method:

>>> newdb = BBDB.fromfile("examples/bbdb.el")
>>> newdb
<BBDB: 2 records>

>>> newdb == db
True

The read() and read_file() methods of a BBDB database can be used import records from other databases.

Exporting to other formats

Since all BBDB objects are subclasses of OrderedDict, you can easily serialize it to other formats. For example, JSON:

>>> import sys
>>> import json
>>> json.dump(db, sys.stdout, indent=4)  # doctest: +NORMALIZE_WHITESPACE +REPORT_UDIFF
{
    "coding": "utf-8-emacs",
    "fileversion": 6,
    "records": [
        {
            "firstname": "Barney",
            "lastname": "Rubble",
            "company": "",
            "aka": [],
            "phone": {},
            "address": {},
            "net": [],
            "fields": {}
        },
        {
            "firstname": "Fred",
            "lastname": "Flintstone",
            "company": "Slate Rock & Gravel",
            "aka": [
                "Freddie"
            ],
            "phone": {
                "Home": "555-1234",
                "Work": "555-6789"
            },
            "address": {
                "Home": {
                    "location": [
                        "Cave 2a",
                        "345 Cavestone Road"
                    ],
                    "city": "Bedrock",
                    "state": "Hanna Barbera",
                    "zipcode": "12345",
                    "country": "USA"
                }
            },
            "net": [
                "fred@bedrock.org",
                "fred.flintstone@gravel.com"
            ],
            "fields": {
                "catchphrase": "\"Yabba dabba doo!\"",
                "kids": "Pebbles, Bam-Bam",
                "spouse": "Wilma"
            }
        }
    ]
}

You can create a BBDB database from an appropriately-structured dict using the fromdict method:

>>> serialized = json.dumps(db)
>>> data = json.loads(serialized)
>>> newdb = BBDB.fromdict(data)
>>> newdb == db
True

Release history

Version 0.3 (22 July 2015)

  • Bugfix: get things working properly with Python 3.

Version 0.2 (2 July 2015)

  • Add validation of data using voluptuous.
  • Add a bunch of demo converter programs.
  • Add tox test support.
  • Add Python 3 support.
  • Bugfix: convert records from file to correct type.

Version 0.1 (11 June 2015)

  • Initial release.

Feedback

Report any problems, bugs, etc, to me (Glenn Hutchings) at zondo42@gmail.com. Patches will also be welcome!

Release History

Release History

0.3

This version

History Node

TODO: Figure out how to actually get changelog content.

Changelog content for this version goes here.

Donec et mollis dolor. Praesent et diam eget libero egestas mattis sit amet vitae augue. Nam tincidunt congue enim, ut porta lorem lacinia consectetur. Donec ut libero sed arcu vehicula ultricies a non tortor. Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Show More

0.2

History Node

TODO: Figure out how to actually get changelog content.

Changelog content for this version goes here.

Donec et mollis dolor. Praesent et diam eget libero egestas mattis sit amet vitae augue. Nam tincidunt congue enim, ut porta lorem lacinia consectetur. Donec ut libero sed arcu vehicula ultricies a non tortor. Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Show More

0.1

History Node

TODO: Figure out how to actually get changelog content.

Changelog content for this version goes here.

Donec et mollis dolor. Praesent et diam eget libero egestas mattis sit amet vitae augue. Nam tincidunt congue enim, ut porta lorem lacinia consectetur. Donec ut libero sed arcu vehicula ultricies a non tortor. Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Show More

Download Files

Download Files

TODO: Brief introduction on what you do with files - including link to relevant help section.

File Name & Checksum SHA256 Checksum Help Version File Type Upload Date
pybbdb-0.3-py2.py3-none-any.whl (17.3 kB) Copy SHA256 Checksum SHA256 2.7 Wheel Jul 22, 2015
pybbdb-0.3.tar.gz (25.8 kB) Copy SHA256 Checksum SHA256 Source Jul 22, 2015
pybbdb-0.3.zip (35.7 kB) Copy SHA256 Checksum SHA256 Source Jul 22, 2015

Supported By

WebFaction WebFaction Technical Writing Elastic Elastic Search Pingdom Pingdom Monitoring Dyn Dyn DNS HPE HPE Development Sentry Sentry Error Logging CloudAMQP CloudAMQP RabbitMQ Heroku Heroku PaaS Kabu Creative Kabu Creative UX & Design Fastly Fastly CDN DigiCert DigiCert EV Certificate Rackspace Rackspace Cloud Servers DreamHost DreamHost Log Hosting