|
1 |
| -# InterBase Driver for Python, supporting 32-bit and 64-bit |
| 1 | +# InterBase Driver for Python |
2 | 2 |
|
3 |
| -[InterBase Documentation](https://docwiki.embarcadero.com/InterBase/2020/en/Main_Page) \* |
4 |
| -[InterBase Source](https://github.com/Embarcadero/InterBasePython) \* |
5 |
| -[Based On FDB](http://www.firebirdsql.org/en/devel-python-driver/) |
| 3 | +<a href="https://www.embarcadero.com/br/products/interbase"><img alt="InterBase" src="https://d2ohlsp9gwqc7h.cloudfront.net/images/logos/logo-page/ib-logo-1024.png" align="right" width="250"></a> |
6 | 4 |
|
7 |
| -Changes implemented are based on this blog post |
| 5 | +> A powerful, [PEP-249-compliant](https://peps.python.org/pep-0249/) Python driver for **InterBase**, supporting both 32-bit and 64-bit. |
8 | 6 |
|
9 |
| -InterBase Driver for Python is a [Python](http://python.org) library package that implements |
10 |
| -[Python Database API 2.0](http://www.python.org/dev/peps/pep-0249/)-compliant support for the Embarcadero SQL Database |
11 |
| -[InterBase](https://interbase.com/) ®. In addition to the minimal |
12 |
| -feature set of the standard Python DB API, InterBase Driver for Python also exposes the entire |
13 |
| -native (old-style) client API of the database engine. Notably: |
| 7 | +The **InterBase Driver for Python** is based on the [FDB driver](http://www.firebirdsql.org/en/devel-python-driver/) and provides access to the [InterBase](https://interbase.com/) RDBMS using a robust and flexible Python interface. This package supports the **Python Database API 2.0** standard (PEP-249) while offering extended access to the native InterBase API. |
14 | 8 |
|
15 |
| - - Automatic data conversion from strings on input. |
16 |
| - - Automatic input/output conversions of textual data between UNICODE |
17 |
| - and database character sets. |
18 |
| - - Support for prepared SQL statements. |
19 |
| - - Multiple independent transactions per single connection. |
20 |
| - access specifications. |
21 |
| - - Distributed transactions. |
| 9 | +📚 [InterBase Documentation](https://docwiki.embarcadero.com/InterBase/2020/en/Main_Page) |
| 10 | +🔗 [GitHub Source Code](https://github.com/Embarcadero/InterBasePython) |
22 | 11 |
|
23 |
| -Install (32-bit or 64-bit version of python 3.* required) |
| 12 | +--- |
24 | 13 |
|
25 |
| -You can use one of the following ways to do it. |
| 14 | +## ✨ Features |
26 | 15 |
|
27 |
| -`pip install interbase` |
| 16 | +- PEP-249 compliance |
| 17 | +- Full Unicode and character set support |
| 18 | +- Native API access |
| 19 | +- Multiple independent transactions per connection |
| 20 | +- Distributed transaction support |
| 21 | +- Automatic conversion of textual data |
| 22 | +- Prepared statement support |
28 | 23 |
|
29 |
| -`pip install git+https://github.com/Embarcadero/InterBasePython.git` |
| 24 | +--- |
30 | 25 |
|
31 |
| -`pip install git+ssh://git@github.com/Embarcadero/InterBasePython.git` |
| 26 | +## 📦 Installation |
32 | 27 |
|
33 |
| -To create a test DB: |
| 28 | +> Requires Python 3.x (32-bit or 64-bit version to match InterBase client). |
34 | 29 |
|
35 |
| -`cd test/files && isql -i create-test-db.sql` |
| 30 | +Install via PyPI: |
| 31 | +```bash |
| 32 | +pip install interbase |
| 33 | +``` |
| 34 | + |
| 35 | +Or install from the GitHub repository: |
| 36 | +```bash |
| 37 | +pip install git+https://github.com/Embarcadero/InterBasePython.git |
| 38 | +# or via SSH: |
| 39 | +pip install git+ssh://git@github.com/Embarcadero/InterBasePython.git |
| 40 | +``` |
| 41 | + |
| 42 | +--- |
| 43 | + |
| 44 | +## 🧪 Setting Up a Test Database |
| 45 | + |
| 46 | +```bash |
| 47 | +cd test/files |
| 48 | +isql -i create-test-db.sql |
| 49 | +``` |
| 50 | + |
| 51 | +--- |
| 52 | + |
| 53 | +## 🔌 Sample Usage |
| 54 | + |
| 55 | +### Basic Connection |
| 56 | +```python |
| 57 | +import interbase |
| 58 | + |
| 59 | +con = interbase.connect( |
| 60 | + host=IBTEST_HOST, # Hostname or IP address of the InterBase server |
| 61 | + database=IBTEST_DB_PATH, # Path to the database file on the server |
| 62 | + user=IBTEST_USER, # Username for authentication |
| 63 | + password=IBTEST_PASSWORD, # Password for authentication |
| 64 | + sql_dialect=IBTEST_SQL_DIALECT, # SQL dialect to use (usually 1 or 3) |
| 65 | + ssl=IBTEST_SERVER_PUBLIC_FILE is not None, # Enable SSL if a public server key is provided |
| 66 | + server_public_file=IBTEST_SERVER_PUBLIC_FILE # Path to the server's public SSL key file (if SSL is enabled) |
| 67 | +) |
| 68 | +``` |
| 69 | + |
| 70 | +### Executing a Query |
| 71 | +```python |
| 72 | +cur = con.cursor() |
| 73 | +cur.execute("SELECT * FROM employees") |
| 74 | +for row in cur: |
| 75 | + print(row) |
| 76 | +``` |
| 77 | + |
| 78 | +### Using Parameters |
| 79 | +```python |
| 80 | +cur.execute("INSERT INTO employees(name, age) VALUES (?, ?)", ("John Doe", 34)) |
| 81 | +con.commit() |
| 82 | +``` |
| 83 | + |
| 84 | +### Handling Transactions |
| 85 | + |
| 86 | +#### Manual Transaction Control |
| 87 | +```python |
| 88 | +transaction = con.main_transaction |
| 89 | +transaction.begin() |
| 90 | + |
| 91 | +cursor = transaction.cursor() |
| 92 | +cursor.execute("INSERT INTO t (c1) VALUES (1)") |
| 93 | +transaction.commit() |
| 94 | +``` |
| 95 | + |
| 96 | +#### Using a Context Manager |
| 97 | +```python |
| 98 | +import interbase |
| 99 | + |
| 100 | +with interbase.TransactionContext(con) as tr: |
| 101 | + cursor = tr.cursor() |
| 102 | + cursor.execute("INSERT INTO t (c1) VALUES (1)") |
| 103 | +# The transaction is automatically committed when the block ends. |
| 104 | +``` |
| 105 | + |
| 106 | +--- |
| 107 | + |
| 108 | +## 🧰 More Examples |
| 109 | +Explore the `test` folder in the [GitHub Repository](https://github.com/Embarcadero/InterBasePython) for full coverage of features, including: |
| 110 | + |
| 111 | +- Working with BLOBs |
| 112 | +- Using metadata APIs |
| 113 | +- Working with stored procedures |
| 114 | +- SSL support |
| 115 | +- Error handling |
| 116 | + |
| 117 | +--- |
| 118 | + |
| 119 | +## 🤝 Contributing |
| 120 | +Pull requests are welcome! For major changes, please open an issue first to discuss what you would like to change. |
| 121 | + |
| 122 | +--- |
| 123 | + |
| 124 | +## 📜 License |
| 125 | +This project is licensed under the Embarcadero license terms. |
| 126 | + |
| 127 | +--- |
| 128 | + |
| 129 | +> 🔗 Stay up to date with the latest changes and enhancements to InterBase by following the official [Embarcadero Blog](https://blogs.embarcadero.com/). |
0 commit comments