DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Please enter at least three characters to search
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Zones

Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks

Last call! Secure your stack and shape the future! Help dev teams across the globe navigate their software supply chain security challenges.

Modernize your data layer. Learn how to design cloud-native database architectures to meet the evolving demands of AI and GenAI workloads.

Releasing software shouldn't be stressful or risky. Learn how to leverage progressive delivery techniques to ensure safer deployments.

Avoid machine learning mistakes and boost model performance! Discover key ML patterns, anti-patterns, data strategies, and more.

Related

  • Instant APIs With Copilot and API Logic Server
  • Instant Integrations With API and Logic Automation
  • REST API Microservice AI Design and Spreadsheet Rules
  • CockroachDB TIL: Volume 11

Trending

  • The Role of Functional Programming in Modern Software Development
  • Teradata Performance and Skew Prevention Tips
  • Microsoft Azure Synapse Analytics: Scaling Hurdles and Limitations
  • Understanding Java Signals
  1. DZone
  2. Data Engineering
  3. Databases
  4. Upgrading a Database Project to Python 3.12

Upgrading a Database Project to Python 3.12

Upgrading to Python versions can be tricky, particularly for Python 3.12. This article describes an experience for a database-oriented project.

By 
Val Huber user avatar
Val Huber
DZone Core CORE ·
Apr. 03, 24 · Tutorial
Likes (2)
Comment
Save
Tweet
Share
1.3K Views

Join the DZone community and get the full member experience.

Join For Free

Upgrading to major versions of Python (e.g., 3.12) can be non-trivial; here's a good article for reference. I recently upgraded API Logic Server, and offer this information in hopes it can make things a bit easier for you.

Aside: API Logic Server is open source. It creates executable API/Admin App projects from a database with 1 command. Customize with rules and Python in your IDE.

There were 2 areas that required attention:

  1. Packaging: Preparing a project for pip installaccess
    • This issue was unique to Python 3.12: the old setup procedures have been removed.
  2. Dependent libraries: This is a consideration for any new release. In general, I found this page helpful.

My project is database-oriented (using SQLAlchemy), so key risk areas usually involve database access. MySQL and Oracle are generally straightforward, but I always need to address Postgres (psycopg) and SQL/Server (pyodbc). These affect requirements.txt and product packaging. 

Let's consider packaging first.

Project Packaging

My project requires packaging for PyPi. This has changed in Python 3.12.

Let's go over some quick background. To make a package available for pip install, you must upload it to PyPi. Here's an uploaded example. This is 2 step process as follows:

  1. Build local install files: This gathers your dependent libraries, CLI entry points, and so forth.
  2. Upload to PyPi: This is unchanged: python3 -m twine upload --skip-existing dist/*. 

The first step has changed in two ways:

  1. How you run the setup process
  2. How you specify your dependent libraries

Run Setup (Dependencies)

This process prepares for python3 -m twine upload..., by creating local files that identify the libraries you require, CLI entry points, and so forth.

In the past, you ran python3 setup.py sdist bdist_wheel. That is no longer supported. It has been replaced by:

python3 -m build

 

pyproject.toml (Not setup.py)

In the past, your setup.py file identified the libraries you require, CLI entry points, and so forth. setup.py is no longer supported in Python 3.12. Instead, you must provide a pyproject.toml file, as described in this guide. The python3 -m build uses this file.

For me, this set off a mild panic: I was unable to find a setup-to-toml migration utility, except for those looking to replace the entire pip install workflow.

As it turned out, migrating setup.py was not so painful by hand; mainly a series of copy/paste procedures as shown below. Here's a working pyproject.toml shown in the diagram below.

Working pyproject.toml

psycopg2-binary: Postgres

This is used by SQLAlchemy for Postgres access. In addition to pyproject.toml, I had to change requirements.txt, as shown here. I changed psycopg2-binary==2.9.5 to:

psycopg2-binary==2.9.9


My project is large, so I found it convenient to create a small venv, and test the install. It took a few tries to straighten out the -binary bit. 

odbc: SQL/Server

Microsoft SQL/Server requires 3 packages (this on a Mac): 

unixodbc

Install unixobdbc. You might get:

==> Running `brew cleanup unixodbc`...
Disable this behaviour by setting HOMEBREW_NO_INSTALL_CLEANUP.
Hide these hints with HOMEBREW_NO_ENV_HINTS (see `man brew`).
Removing: /opt/homebrew/Cellar/unixodbc/2.3.11... (48 files, 2.3MB)
Warning: The following dependents of upgraded formulae are outdated but will not
be upgraded because they are not bottled:
  msodbcsql18
(venv) val@Vals-MPB-14 Desktop % 


It seemed to work.

odbc driver

I required the Microsoft odbc driver.

pyodbc

This is used by SQLAlchemy. In requirements.txt and pyproject.toml, I had to change pyodbc==4.0.34 --> pyodbc==5.0.0.

Minor Issues: Escape Characters

As noted in Python docs, mistakes in strings (e.g., \but I forgot the n) were previously not flagged; now they are.

I mention this because unexpected messages show up when you start your program under the debugger.

API Database Integrated development environment MySQL Python (language)

Opinions expressed by DZone contributors are their own.

Related

  • Instant APIs With Copilot and API Logic Server
  • Instant Integrations With API and Logic Automation
  • REST API Microservice AI Design and Spreadsheet Rules
  • CockroachDB TIL: Volume 11

Partner Resources

×

Comments
Oops! Something Went Wrong

The likes didn't load as expected. Please refresh the page and try again.

ABOUT US

  • About DZone
  • Support and feedback
  • Community research
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Core Program
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 100
  • Nashville, TN 37211
  • support@dzone.com

Let's be friends:

Likes
There are no likes...yet! 👀
Be the first to like this post!
It looks like you're not logged in.
Sign in to see who liked this post!