Skip to content

Commit 27e622c

Browse files
committed
Update README for release
1 parent 2573645 commit 27e622c

3 files changed

Lines changed: 62 additions & 5 deletions

File tree

README.md

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,59 @@
11
# polars_access_mdbtools
22
A library for reading tables from an Access database into Polars dataframes, using mdbtools
3+
4+
## What is this?
5+
6+
A tiny, `subprocess`-based tool for reading a
7+
[MS Access](https://products.office.com/en-us/access)
8+
database (`.rdb`) as a [Python Polars Dataframe](https://docs.pola.rs).
9+
10+
## Installation
11+
12+
To read the database, this package thinly wraps
13+
[MDBTools](https://github.com/mdbtools/mdbtools).
14+
15+
If you are on `OSX`, install it via [Homebrew](http://brew.sh/):
16+
17+
```sh
18+
$ brew install mdbtools
19+
```
20+
21+
If you are on `Debian`, install it via apt:
22+
```sh
23+
$ sudo apt install mdbtools
24+
```
25+
26+
If you are on `Windows`, it's a little tougher. Install `mdbtools` for [Windows](https://github.com/lsgunth/mdbtools-win). Manually add to PATH.
27+
1. Download the mdb-tools files from Windows link above. Visit the Releases section, then downloadi the part that says "Source Code (zip)".
28+
2. Extract that to somewhere like `C:/bin/mdbtools-win/mdbtools-win-1.0.0`.
29+
3. Follow these instructions to [add that folder to your environment path](https://linuxhint.com/add-directory-to-path-environment-variables-windows/) (Method 1, but use the path to the mdbtools executable files).
30+
4. Restart your computer or just close and re-open the program you're running it from. You can test that it works by opening a terminal and running `mdb-tables --help` and see that it doesn't fail.
31+
32+
Finally, on all OS's:
33+
```sh
34+
$ pip install polars_access_mdbtools
35+
```
36+
37+
## Example Usage
38+
39+
```python
40+
import polars as pl
41+
import polars_access_mdbtools as pl_access
42+
43+
file_path = 'path_to_file.mdb'
44+
pl_access.list_table_names(file_path)
45+
46+
df = pl_access.read_table(file_path, table_name='your_table_name')
47+
48+
```
49+
50+
## Acknowledgements
51+
52+
This code is based heavily on [jbn's `pandas_access` library](https://github.com/jbn/pandas_access).
53+
54+
## Contributing
55+
56+
Please Star this repo.
57+
58+
Please submit bug reports as GitHub Issues. Feel free to submit a PR to fix an issue!
59+

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ classifiers = [
1313
"Operating System :: OS Independent",
1414
]
1515
dependencies = [
16-
"polars",
16+
"polars >= 0.20",
1717
]
1818

1919
[project.urls]

src/polars_access_mdbtools/__init__.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ def list_table_names(rdb_file: Union[str, os.PathLike], encoding: str = 'utf-8')
2020
:param encoding: The content encoding of the output of the mdb-tables command.
2121
:return: A list of the tables in a given database.
2222
"""
23-
tables = subprocess.check_output(['mdb-tables', "--single-column", rdb_file]).decode(encoding)
23+
tables = subprocess.check_output(['mdb-tables', "--single-column", str(rdb_file)]).decode(encoding)
2424
return tables.strip().split("\n")
2525

2626

@@ -92,7 +92,7 @@ def _read_table_mdb_schema(rdb_file: Union[str, os.PathLike], table_name: str, e
9292
'--no-indexes',
9393
'--no-relations',
9494
'--table', table_name,
95-
rdb_file]
95+
str(rdb_file)]
9696
cmd_output = subprocess.check_output(cmd)
9797
cmd_output = cmd_output.decode(encoding)
9898
lines = cmd_output.splitlines()
@@ -163,7 +163,7 @@ def read_table(rdb_file: Union[str, os.PathLike], table_name: str, data_encoding
163163
else:
164164
pl_schema_read[col_name] = col_type
165165

166-
cmd = ['mdb-export', '--bin=hex', '--date-format', '%Y-%m-%d', '--datetime-format', '%Y-%m-%dT%H:%M:%S', rdb_file, table_name]
166+
cmd = ['mdb-export', '--bin=hex', '--date-format', '%Y-%m-%d', '--datetime-format', '%Y-%m-%dT%H:%M:%S', str(rdb_file), table_name]
167167

168168
# Debug:
169169
# data_str = subprocess.check_output(cmd).decode(data_encoding)
@@ -175,7 +175,7 @@ def read_table(rdb_file: Union[str, os.PathLike], table_name: str, data_encoding
175175

176176
with warnings.catch_warnings():
177177
warnings.filterwarnings("ignore", message="Polars found a filename.*")
178-
178+
179179
df = pl.read_csv(
180180
proc.stdout,
181181
schema=pl_schema_read,

0 commit comments

Comments
 (0)