First class support for psycopg2cffi

Issue #3052 resolved
Alex Gaynor created an issue

It'd be great if there was first class support for psycopg2cffi (the name is pretty straightforward :P), which is the best drive for PostgreSQL on PyPy. I suspect it basically just works; adding it to the test matrix is valuable.

Comments (11)

  1. Mike Bayer repo owner

    OK well we can try it without any code changes first like this:

    import psycopg2cffi
    e = create_engine("postgresql+psycopg2://user:pass@host/db", module=psycopg2cffi)
    

    then to actually support it, we just need to add a psycopg2cffi.py file with pretty much a three line stub dialect, that subclasses PGDialect_psycopg2:

    class PGDialect_psycopg2cffi(PGDialect_psycopg2):
        driver = 'psycopg2cffi'
    
        @classmethod
        def dbapi(cls):
            import psycopg2cffi
            return psycopg2cffi
    

    that would be it!

  2. Alex Gaynor reporter

    It imports as psycopg2cffi, there's a .compat() method you can use for it to monkey patch its way to being psycopg2, but I think it's better to discourage that.

  3. Mike Bayer repo owner
    • additional test adjustments for pypy / psycopg2cffi. This consists mainly of adjusting fixtures to ensure connections are closed explicitly. psycopg2cffi also handles unicode bind parameter names differently than psycopg2, and seems to possibly have a little less control over floating point values at least in one test which is marked as a "fail", though will see if it runs differently on linux than osx..
    • changelog for psycopg2cffi, fixes #3052

    → <<cset a826ff366bf9>>

  4. zoomorph

    In testing my app, I'm seeing ~2x slower performance (as timed with @event.listens_for(Engine, 'before_cursor_execute') methods) for queries, flushes and commits using pypy+sqlalchemy1.0+psycopg2cffi compared with cpython+sqlalchemy1.0+psycopg2. I'm guessing this has little to do with SQLAlchemy, though.

  5. Log in to comment