Synopsis
The pyficache module allows one to get any line from any file, caching lines of the file on first access to the file. Although the file may be any file, this package is more tailored to the case where the file is a Python script.
Here, the file is parsed to determine statement boundaries, and a copies of the file syntax-highlighted are also saved.
Also saved is file information, such as when the file was last modified and a SHA1 of the file. These are useful in determining if the file has changed and verifying the contents of the file.
By caching contents, access is sped up when small random sets of lines are read from a single file, in particular in a debugger, to show source lines.
A file path can be remapped to another path. This is useful, for example, when debugging remotely, and the remote file path may be different from the path on a local filesystem. In the trepan3k and trepan2 debuggers, eval and exec strings are saved in a temporary file and then the pseudo-filename <string> is remapped to that temporary file name.
Similarly, lines within a file can be remapped to other lines. This may be useful in preprocessors or template systems where one wants to make a correspondence between the template file and the expanded Python file as seen in a tool using that underlying Python file, such as a debugger or profiler.
Summary
import pyficache
filename = __file__ # e.g. '/tmp/myprogram'
# return all lines of filename as an array
lines = pyficache.getlines(filename)
# return line 6, and reload all lines if the file has changed.
line = pyficache.getline(filename, 6, {'reload_on_change': True})
# return line 6 syntax highlighted via pygments using style 'colorful'
line = pyficache.getline(filename, 6, {'style': 'colorful'})
pyficache.remap_file('/tmp/myprogram.py', 'another-name')
line_from_alias = pyficache.getline('another-name', 6)
assert __file__, pyficache.remove_remap_file('another-name')
# another-name is no longer an alias for /tmp/myprogram
assert None, pyficache.remove_remap_file('another-name')
# Clear cache for __file__
pyficache.clear_file_cache(__file__)
# Clear all cached files.
pyficache.clear_file_cache()
# Check for modifications of all cached files.
pyficache.update_cache()
Credits
This is a port of my Ruby linecache module, which in turn is based on the Python linecache module.
xdis provides the cool stuff to figure out the lines containing Python statements.
Release files for pyficache 2.6.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| pyficache-2.6.0.tar.gz | 40.6 kB | Details |
Built distributions (wheels)
| File | Reset | |||
|---|---|---|---|---|
| pyficache-2.6.0-py314-none-any.whl | Python 3.14 | none | any | Details |
| pyficache-2.6.0-py313-none-any.whl | Python 3.13 | none | any | Details |
| pyficache-2.6.0-py312-none-any.whl | Python 3.12 | none | any | Details |
| pyficache-2.6.0-py311-none-any.whl | Python 3.11 | none | any | Details |
| pyficache-2.6.0-py310-none-any.whl | Python 3.10 | none | any | Details |
| pyficache-2.6.0-py39-none-any.whl | Python 3.9 | none | any | Details |
| pyficache-2.6.0-py38-none-any.whl | Python 3.8 | none | any | Details |
| pyficache-2.6.0-py37-none-any.whl | Python 3.7 | none | any | Details |
| pyficache-2.6.0-py36-none-any.whl | Python 3.6 | none | any | Details |
Total release size: 383.3 kB
Release files / pyficache-2.6.0.tar.gz
| Download URL | pyficache-2.6.0.tar.gz |
|---|---|
| Size | 40.6 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
4534639b115cd87c6a739890f47b9140c50cde03f42356f8704701212667f9f6
|
|
BLAKE2b-256 checksum How to use checksums |
50fdd067e47cbd23b70926eca03c6b48156ea65e5b94b6c45ca492fabced30a0
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.13.12
|
Release files / pyficache-2.6.0-py314-none-any.whl
| Download URL | pyficache-2.6.0-py314-none-any.whl |
|---|---|
| Size | 35.3 kB |
| Tags | Python 3.14 |
|
SHA-256 checksum How to use checksums |
da514d1276cc59dd04631248370702eaf7d489b0d682e07fcbce66fec299dd07
|
|
BLAKE2b-256 checksum How to use checksums |
5ca940173977d55281fd836807a0c1d7bce760f9255fd9c1523310191d5b7f0e
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.14.3
|
Release files / pyficache-2.6.0-py313-none-any.whl
| Download URL | pyficache-2.6.0-py313-none-any.whl |
|---|---|
| Size | 35.3 kB |
| Tags | Python 3.13 |
|
SHA-256 checksum How to use checksums |
e612545e35fef58a3bb4ad849a72338e5bf16f6cf7afa327bd425d1038e714b0
|
|
BLAKE2b-256 checksum How to use checksums |
f85e8921796e1074b76a342629a56638b2d7d2522c684d24518e23dc2cefe624
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.14.3
|
Release files / pyficache-2.6.0-py312-none-any.whl
| Download URL | pyficache-2.6.0-py312-none-any.whl |
|---|---|
| Size | 35.3 kB |
| Tags | Python 3.12 |
|
SHA-256 checksum How to use checksums |
1da3db4f1495afcfc1bccbf407bb0973a88b9dd375ec81eb3602322177274be8
|
|
BLAKE2b-256 checksum How to use checksums |
4603935413980994f30cf07627a88900fba98cdcdbcfd226585636439680b0b1
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.14.3
|
Release files / pyficache-2.6.0-py311-none-any.whl
| Download URL | pyficache-2.6.0-py311-none-any.whl |
|---|---|
| Size | 35.3 kB |
| Tags | Python 3.11 |
|
SHA-256 checksum How to use checksums |
94f720edc31146f6c64c4d43919e85e30ef896861926fe4fdde479755bad44ae
|
|
BLAKE2b-256 checksum How to use checksums |
541ca824cffda36c7fd2be526ea0cf0c99c20ca1477a4b19688b4eed014e970b
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.14.3
|
Release files / pyficache-2.6.0-py310-none-any.whl
| Download URL | pyficache-2.6.0-py310-none-any.whl |
|---|---|
| Size | 40.3 kB |
| Tags | Python 3.10 |
|
SHA-256 checksum How to use checksums |
ea90f129e8c6c615aadaa153df1e4fca3d8cc5f5b8dd05d5782ce766af8ccce3
|
|
BLAKE2b-256 checksum How to use checksums |
1a7bccb0216357a0833f58a4a2f4ac219626a4c5df9b786bb80c5ade9bb9f0de
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.13.12
|
Release files / pyficache-2.6.0-py39-none-any.whl
| Download URL | pyficache-2.6.0-py39-none-any.whl |
|---|---|
| Size | 40.3 kB |
| Tags | Python 3.9 |
|
SHA-256 checksum How to use checksums |
d16f090c8d0c79e8841558f1f0cc3849b58c1c058b39ce12895bb6f2bf44c813
|
|
BLAKE2b-256 checksum How to use checksums |
62d00e748fd4b3269cae3fd46a858f91e69c70b0e7d9b5752b44c0be74fa86b4
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.13.12
|
Release files / pyficache-2.6.0-py38-none-any.whl
| Download URL | pyficache-2.6.0-py38-none-any.whl |
|---|---|
| Size | 40.3 kB |
| Tags | Python 3.8 |
|
SHA-256 checksum How to use checksums |
3d5826e210d19ac50cb91ba2a91ce4214f118f0ce884d8d940af1a1ee99233e3
|
|
BLAKE2b-256 checksum How to use checksums |
73d9e481c89e60566f01dcd004a1e51513de7f2126935d3c0106701fb0003328
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.13.12
|
Release files / pyficache-2.6.0-py37-none-any.whl
| Download URL | pyficache-2.6.0-py37-none-any.whl |
|---|---|
| Size | 40.2 kB |
| Tags | Python 3.7 |
|
SHA-256 checksum How to use checksums |
504a1ca12282da48a6c55ea0f9bef22b291f86106282f88056fc67bd5a2dbdf5
|
|
BLAKE2b-256 checksum How to use checksums |
ceb89a9b849acf7bff409e59c61cbbc0191d3fd1cadbb3bbf2852a47ea256b4b
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.13.12
|
Release files / pyficache-2.6.0-py36-none-any.whl
| Download URL | pyficache-2.6.0-py36-none-any.whl |
|---|---|
| Size | 40.3 kB |
| Tags | Python 3.6 |
|
SHA-256 checksum How to use checksums |
e3bcb7100d2b85791997a6f4c29135bf6d63fa67268a562a1b5f7839e287a883
|
|
BLAKE2b-256 checksum How to use checksums |
28fdcfaaa4d02f5a4990b581a2d1e806c62c61ed6bc34ab6212dc7fc1fa056bb
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.13.12
|