csingley / ofxtools

Python OFX Library
Other
301 stars 68 forks source link

Cannot import name 'StmtRq' from 'ofxtools' #87

Closed prouderthings closed 4 years ago

prouderthings commented 4 years ago

I may be missing something, but in the docs for the method call using OFXClient in another program, the example shows:

import datetime; import ofxtools
from ofxtools import OFXClient, StmtRq, CcStmtEndRq

When I run this in my virtualenv, I get an ImportError:

Traceback (most recent call last):
  File "download.py", line 3, in <module>
    from ofxtools import OFXClient, StmtRq
ImportError: cannot import name 'StmtRq' from 'ofxtools' (/fin/lib/python3.7/site-packages/ofxtools/__init__.py)

Using pkgutil, I can see the available submodules:

Found submodule Client (is a package: False)
Found submodule Parser (is a package: False)
Found submodule Types (is a package: False)
Found submodule __version__ (is a package: False)
Found submodule config (is a package: True)
Found submodule header (is a package: False)
Found submodule lib (is a package: False)
Found submodule models (is a package: True)
Found submodule ofxhome (is a package: False)
Found submodule scripts (is a package: True)
Found submodule utils (is a package: False)

Any ideas? Using Python 3.7.7, installed with 'pip install ofxtools'

csingley commented 4 years ago

Yeah that's a documentation bug - obsolete syntax, I'll review to fix. What you want is in models, as you might suspect. The actual syntax now looks like this:

In [1]: from ofxtools.models import STMTRQ

csingley commented 4 years ago

OK, so what's your source for the obsolete docs? It doesn't match anything I published here. If I'm somehow delivering to you docs that lag way behind what's installed on your HDD, I need to understand that in order to shut it down.

prouderthings commented 4 years ago

Thanks for the quick response!

My sources are below (example is at the bottom):

Web URL: https://ofxtools.readthedocs.io/en/latest/client.html#using-ofxclient-in-another-program Source URL: https://ofxtools.readthedocs.io/en/latest/_sources/client.rst.txt

csingley commented 4 years ago

Ah gotcha, verified. I was looking in the wrong place. This is a quick & easy fix. Thanks for reporting.

csingley commented 4 years ago

Yeah it's really just the import statement. This works fine for me:

In [1]: import datetime; import ofxtools 
   ...: from ofxtools.Client import OFXClient, StmtRq, CcStmtEndRq 
   ...: client = OFXClient("https://ofx.chase.com", userid="MoMoney", 
   ...:                     org="B1", fid="10898", 
   ...:                     version=220, prettyprint=True, 
   ...:                     bankid="111000614") 
   ...: dtstart = datetime.datetime(2015, 1, 1, tzinfo=ofxtools.utils.UTC) 
   ...: dtend = datetime.datetime(2015, 1, 31, tzinfo=ofxtools.utils.UTC) 
   ...: s0 = StmtRq(acctid="1", accttype="CHECKING", dtstart=dtstart, dtend=dtend) 
   ...: s1 = StmtRq(acctid="2", accttype="SAVINGS", dtstart=dtstart, dtend=dtend) 
   ...: c0 = CcStmtEndRq(acctid="3", dtstart=dtstart, dtend=dtend) 
   ...: response = client.request_statements("t0ps3kr1t", s0, s1, c0)
In [2]: response
Out[2]: <_io.BytesIO at 0x7f5345595900>

I'll post a patch to docs in the Client docstring and in the location you pointed to, and consider that to close this bug.

I really should try to smoke much less crack while trying to close bug reports.