PyCon Braindump

Jacob Kaplan-Moss

March 19, 2008

There are some great roundups of the content at PyCon out there; this isn’t one of them. See, I have this notebook (Moleskine FTW!) I carry with me everywhere, and now it’s chock-full of note from PyCon; this is a braindump.

  • EAV

  • Mammoth replicator

  • Django 1.0 will support Python 2.3, but later releases likely will not. We’ll need to start working on moving to Python 3.0, and that means slowly dropping other Python versions until we reach 2.6 and can start using 2to3.

  • PEP 302.

  • import_in_py

  • You can nest {% regroup %}:

    {% regroup issues|dictsort:"client" by client as client_groups %}
    {% for client_group in client_groups %}
      <h2>{{ client_group.grouper.name }}</h2>
      {% regroup client_group.list|dictsort:"category" by category as category_groups %}
      {% for category_group in category_groups %}
        <h3>{{ category_group.grouper.name }}</h3>
        <ul>
          {% for issue in category_group.list %}
            <li>{{ issue }}</li>
          {% endfor %}
        </ul>
      {% endfor %}
    {% endfor %}
    
  • A pretty standard cache eviction strategy:

    def something_detail(request, something_id):
        key = "something:%s" % something_id
        value = cache.get(key)
        if value is None:
            value = calculate_value(something_id)
            cache.set(key, value, 600)
        return do_something_with(value)
    
    ...
    
    class Something(Model):
        ...
    
        def save(self):
            cache.delete("something:%s" % self.id)
    
  • Trestle:

    Trestle is a nose plugin that enables you to write testable documentation for web apps (or shell commands, but more on that later).

    To use trestle, write a reStructured Text document using a set of special directives to indicate the fixtures to be used for testing (including the http or mock http client), each request to be sent via the client, and the expected response from the application under test.

    Nice!

  • Saturday House

  • Thrift

  • pyxpcomext

  • haufe.eggserver

  • argparse

  • PythonSpeakers

  • Supervisor

  • Guns don’t kill people; Magic Missiles do.”

  • This, apparently, is the year of Django on alternate VMs:

    • Django on Jython
    • Django on IronPython
    • I also saw a demo of Django on PyPy, but can’t seem to find a writeup. It’s not totally working yet because of some of the juju we do in django.dispatch, but that’ll be fixed (on our end, that is) shortly.

    I think this means that Django is the first web framework to run on four different VMs. Wonder if anyone’s working on Django on Parrot…

  • Speaking of PyPy, the sandbox is amazing.

  • Signals are finally getting a rewrite:

    class_prepared = Signal(...)
    
    ...
    
    class_prepared.connect(listener)
    
    ...
    
    class_prepared.send()
    

    The old API will still work, of course.

  • SnapLogic

  • SNPedia

  • python4ply

    for line in open("python_yacc.py"):
        if line =~ m/def (\w+)/:
            print repr($1)
    

    I can’t decide if this is brilliant or disgusting. Both, I suppose.

  • pvote:

    Pvote is prototype software for electronic voting machines. […] The current version is 460 lines of Python.

  • Transitive Grace Period Public License (“TGPPL”)

  • A few different takes on concurrency in Python:

  • An idea for multiple database connections:

    from django.db import connection
    
    class SomeOtherDatabase(connection.Connection):
        engine = "sqlite3"
        name = "/tmp/whatever.db"
    
    ...
    
    # Import data from the other database...
    OtherPerson = SomeOtherDatabase.ModelWrapper(Person)
    for p in OtherPerson.objects.all():
        Person.objects.create(**p.__dict__)
    
  • We’re improving INSTALLED_APPS:

    INSTALLED_APPS = (
        "some.app",
        app("some.app", label="other", db_prefix="whoa_")
    )
    
  • WebError

I need some more sleep.

Comments:

Erik:

Re: improving INSTALLED_APPS: Does this mean it'll be possible to have duplicate apps? (I'm using a generic blogging app for my wife and me, on the same site, and would rather have separate interfaces & db tables than having to filter on a user foreignkey or other author-identifier.)

Adrian Holovaty:

Erik: Yes, we aim to make that possible.

Alex Ezell:

Multiple database connections: I dream about this at night. Laugh all you want, but it'd make Django a big winner here. :)

Erik:

@Adrian (& the Django gods): YAY! (& in all seriousness.)

Jeremy:

@Jacob: On "A pretty standard cache eviction strategy:"
Consider, also, that instead of just doing cache.delete on model.save, you could also make an async request to gearman to rebuild that key (or to add to a list of things to be re-built at some point).

Jan Oberst:

Yay from me, too!

Stuart:

I also dream of a Django that can talk to the 7-8 databases that I have to talk to at the same time.

Is it really this hard? time seems to fly, and an answer to this problem seems to be stuck somewhere... I cannot quite see why.

For 0.97 to finally include a trunk support in almost any way for this critical feature would enable a lot more use here.

To give you an idea of the scale, if I got this in the next few weeks, it would enable me to spec Django as the basis of out entire election information system for this years general election (guess the country, and it does not start with a 'U'), but without that, it cannot be done, simple as that - as we do not control the database structures.

Daryl Spitzer:

@Stuart, keep an eye on ticket 1142 (http://code.djangoproject.c...). I've taken it, and I hope to get a prototype working today (the last day of the sprint). I'll attach a patch as soon as I have something that seems to work so others can test it.

Darren Pearce:

I'd love to see the multiple database sorted, but why the need for the database name in the code? When the app itself should handle that behind the scenes.

Just a thought.

Why not map applications to databases? in the installed_apps, Then the code again is truly portable.

databases = (
db(id="someUniqueID",name="db.sqlite3",type="sqlite3",),
)

INSTALLED_APPS = (
app("some.app", db_connection="someUniqueID",),
)

thoughts?

Leave a comment:

Use your real name, or risk deletion.

Optional.

No markup allowed. Linebreaks will be converted; links will be linkified.

Be nice; don't be that guy.