I figured this out. Turns out Boost Python was my unknown-unknown here.
There still is no turnkey way to work with ledger in Python, but it is
possible. This is what I did
- Clone the ledger repository locally *gh repo clone ledger/ledger*
- *cd ledger*
- *mkdir build* — this collects all the build artefacts if present; it's
a cleaner way than building in the repository root
- run *./acprep --python dependencies* to ensure ledger dependencies are
installed
- if this does not automatically install *boost-python*, ensure you
have it
- run *./acprep --compiler=c++ --python --ninja*
- I'm on a mac, hence *c++* because of some libraries from Apple
- I kept the *--python* tag cos that's the end goal here
- and *--ninja* is a sweet quiet incremental make
- Copy the built library into your Python project — *cp
build/ledger/debug/ledger.so path/to/your/python-project*`
With this done, you can then *import** ledger* and follow along with
everything in the Extending with Python
<https://ledger-cli.org/doc/ledger3.html#Extending-with-Python> section of
the documentation. One way to test this is to copy *python/demo.py* to the
build directory and run it. It should run fine.
Do I wish there was an easier way to do this, so we can unlock the
innovation of smart Python folks looking to build extensions for ledger and
ending up defaulting to other tools? Yes, I do; but I lack the python-fu
and c++-fu to get this done — please help contribute if you can.
*Igbanam*
On Thu, Feb 6, 2025 at 10:01 PM Igbanam Ogbuluijah <[email protected]>
wrote:
> Hi all,
>
> I'm trying to create some Python wrapper to work with my ledger files. I
> see that there's the Extending with Python
> <https://ledger-cli.org/doc/ledger3.html#Extending-with-Python>; but I
> don't know from what package I should import ledger. I looked through
> PyPi and… doesn't seem like any package there points to a ledger-cli
> extension. I also tried running the python/demo.py in the repository.
> This rightly fails to import ledger as well
>
> $ python demo.py # with [email protected]
> Traceback (most recent call last):
> File "/Users/igbanam/projects/igbanam/ledger/python/demo.py", line 10,
> in <module>
> import ledger
> ModuleNotFoundError: No module named 'ledger'
>
> Please help point me in the right direction.
>
> Thank you
>
>
> *Igbanam*
>
--
---
You received this message because you are subscribed to the Google Groups
"Ledger" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion visit
https://groups.google.com/d/msgid/ledger-cli/CAOmRJrf3JpPSEWg0XbiXnu2j3vZbWwOb%2BxYcZi4Vbz5d%2BWp-yA%40mail.gmail.com.