Pynary - Python Binary provides tools to build binary python packages and upload to pypi
Project description
pynary
Converts python code to binary format
This package converts your python code to binaries for the platforms that you compile it on. It uses cython. It also allows you to push your binary package to pypi with command line parameters.
##Installation instructions:
pip install pynary
Getting Help
pynary provides comprehensive help for all commands:
# Main help
python -m pynary --help
# Build command help
python -m pynary.build --help
# Upload command help
python -m pynary.pypipush --help
# or
python pypipush.py --help
The help text includes examples, usage patterns, and authentication information.
##Requirements: Ideally your package directory structure should look like below:
your_package_name/
|-- your_package_name/
| |-- some_module/
| |-- module3.py
| |-- __init__.py
| |-- module1.py
| |-- module2.py
|-- setup.py
|-- README.md
|-- LICENSE
Make sure some_module does not have init.py in it. your library should have init.py. You need to have a file named setup.py. A sample setup.py looks like below:
import setuptools
from setuptools.dist import Distribution
with open("README.md", "r") as fh:
long_description = fh.read()
class BinaryDistribution(Distribution):
"""Distribution which always forces a binary package with platform name"""
def has_ext_modules(foo):
return True
setuptools.setup(
name="<your_package_name>",
version="<version_number>",
author="<Author name>",
author_email="<author's email address>",
description="<short description>",
long_description=long_description,
long_description_content_type="text/markdown",
url="<URL of your website if any>",
packages=['<your_package_name>'],
include_package_data=True,
install_requires=[
'cryptography',
'numpy',
'mysqleasy',
'pandas',
'zmq',
],
classifiers=[
"Programming Language :: Python :: 3",
"License :: OSI Approved :: GNU General Public License v3 (GPLv3)",
# Platform-specific classifiers (pip uses these to select the correct wheel)
"Operating System :: Microsoft :: Windows",
"Operating System :: POSIX :: Linux",
"Operating System :: MacOS",
],
distclass=BinaryDistribution,
)
Once you have the setup.py created then you could just use the commandline to convert the python code and create a binary package.
##Sample usage
Building Your Package
Basic Build:
python -m pynary -n <your_package_name>
Build Options:
# Clean build (removes existing build directory)
python -m pynary -n <package_name> -f
# or
python -m pynary -n <package_name> --fresh
# Use new build system (python -m build)
python -m pynary -n <package_name> -m
# Verbose output
python -m pynary -n <package_name> -v
# Explicitly specify build command
python -m pynary -c build -n <package_name>
# or short form:
python -m pynary -c b -n <package_name>
Incremental Builds:
- By default, pynary performs incremental builds - only recompiles changed files
- Compiled binaries (
.pyd/.so) are preserved between builds - Cython build cache is stored in
build/cython/directory - Use
-cor--cleanflag for a fresh build
Important Security Note:
- Most Python source files (
.py) are compiled to binary format (.pyd/.so) - However,
__init__.pyand__main__.pyfiles remain as source code in the built package - These files are required for Python package structure but will be visible to users
- If these files contain sensitive code, consider moving it to compiled modules
- A warning will be displayed during build if these files are present
Platform-Specific Wheels:
- pynary automatically builds platform-specific wheels (
.whlfiles) - Wheels are tagged with platform information (e.g.,
win_amd64,linux_x86_64,macosx_10_9_x86_64) - When users run
pip install yourpackage, pip automatically selects the correct wheel for their platform - This ensures each platform gets the correct binary format
Uploading to PyPI:
You can upload using any of these equivalent methods:
# Method 1: Direct script
python pypipush.py -n mypackage -d test
# Method 2: Via module interface (recommended)
python -m pynary -c pypipush -n mypackage -d test
# or short form:
python -m pynary -c p -n mypackage -d test
# Method 3: Direct module import
python -m pynary.pypipush -n mypackage -d test
All three methods are equivalent and support all the same options.
Enhanced PyPI Upload Options
Basic Usage:
# Upload to TestPyPI (all methods are equivalent)
python pypipush.py -n mypackage -d test
python -m pynary -c pypipush -n mypackage -d test
python -m pynary -c p -n mypackage -d test
# Upload to production PyPI
python pypipush.py -n mypackage -d production
python -m pynary -c pypipush -n mypackage -d production
# Dry run (validate without uploading)
python pypipush.py -n mypackage -d production --dry-run
python -m pynary -c p -n mypackage -d production --dry-run
Using API Token (Recommended):
API tokens are the recommended authentication method for PyPI because they:
- Are more secure than passwords (can be revoked without changing your password)
- Can be scoped to specific projects
- Don't require entering credentials interactively
- Work better in CI/CD environments
How to Get a PyPI API Token:
-
Go to PyPI Account Settings:
- Visit https://pypi.org/account/login/
- Log in with your PyPI account
-
Create an API Token:
- Go to https://pypi.org/manage/account/token/
- Click "Add API token"
- Enter a name for the token (e.g., "pynary-upload-token")
- Choose scope:
- Entire account: Token works for all your projects
- Project specific: Token only works for one project (more secure)
- Click "Add token"
- Copy the token immediately - it will only be shown once!
- Format:
pypi-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
- Format:
-
Use the Token:
# Using command line argument
python pypipush.py -n mypackage -d production --token pypi-xxxxxxxxxxxxx
# Using environment variable (recommended for security)
export TWINE_TOKEN=pypi-xxxxxxxxxxxxx
python pypipush.py -n mypackage -d production
# On Windows (PowerShell)
$env:TWINE_TOKEN="pypi-xxxxxxxxxxxxx"
python pypipush.py -n mypackage -d production
# On Windows (CMD)
set TWINE_TOKEN=pypi-xxxxxxxxxxxxx
python pypipush.py -n mypackage -d production
Security Best Practices:
- Never commit tokens to version control
- Use environment variables instead of command-line arguments when possible
- Use project-specific tokens when you only need to upload one package
- Revoke tokens if they're compromised or no longer needed
Using Username/Password:
# Using command line arguments
python pypipush.py -n mypackage -d production --username myuser --password mypass
# Using environment variables
export TWINE_USERNAME=myuser
export TWINE_PASSWORD=mypass
python pypipush.py -n mypackage -d production
Custom Repository:
# Upload to a custom PyPI-compatible repository
python pypipush.py -n mypackage -r https://custom-pypi.example.com/legacy/
Additional Options:
--skip-existing: Skip files that already exist (default: True for production)--verbose: Enable verbose output--dry-run: Validate package without uploading
##Using your package
Once your package is built and uploaded to PyPI, users can install it with:
pip install your_package_name
Platform-Specific Installation:
- When users run
pip install, pip automatically detects their platform - pip selects the correct wheel (Windows
.pyd, Linux/Mac.so) for their system - No additional configuration needed - pip handles platform selection automatically
Important Note on Dependencies:
- Your package built with pynary will install correctly
- However, if your package has dependencies that need compilation (like
blis,numpy, etc.), users may encounter build errors - This happens when dependencies don't have pre-built wheels for the user's platform/Python version
- Solution: Ensure your dependencies are available as pre-built wheels, or document that users need build tools (C compiler, etc.)
- Common dependencies with pre-built wheels:
numpy,pandas,scipy(usually available) - Dependencies that may need compilation:
blis, custom C extensions, etc.
Using the installed package:
from your_package_name import module1
from your_package_name import module3
Cross-Platform Building
Important Limitations:
- Cython compiles to platform-specific binaries (
.pydon Windows,.soon Linux/Mac) - You cannot cross-compile from Windows to macOS - macOS binaries require macOS toolchains
- You cannot cross-compile from Windows to Linux easily - requires Docker or WSL
Practical Solutions:
Option 1: Build on Each Platform
Build on the target platform:
- Windows: Run
python -m pynary -n <package_name>on Windows - Linux: Run the same command on a Linux machine or WSL
- macOS: Run the same command on a macOS machine
Option 2: Use Docker (Linux builds from Windows)
If you have Docker installed, you can build Linux binaries from Windows:
# Build for Linux using Docker
docker run --rm -v "%cd%":/workspace -w /workspace python:3.9 bash -c "pip install pynary && python -m pynary -n <package_name>"
Option 3: Use CI/CD (Recommended)
Use GitHub Actions or similar CI/CD services to build for all platforms automatically:
- GitHub Actions provides free runners for Windows, Linux, and macOS
- Quick Setup: Copy the workflow files from
.github/workflows/in this repository - See
.github/workflows/README.mdfor detailed setup instructions - Two workflows are provided:
build-and-publish.yml: Builds and publishes to PyPI on version tagsbuild-only.yml: Builds and tests without publishing (for CI)
Option 4: Use Virtual Machines
- Use VMs for Linux builds
- Use macOS VMs (requires macOS license) for macOS builds
Note: The most practical approach is to use CI/CD services like GitHub Actions, which can build for all three platforms automatically without requiring local setup for each platform.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distributions
Built Distributions
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file pynary-0.1.0-py3-none-manylinux2014_x86_64.manylinux_2_17_x86_64.whl.
File metadata
- Download URL: pynary-0.1.0-py3-none-manylinux2014_x86_64.manylinux_2_17_x86_64.whl
- Upload date:
- Size: 1.6 MB
- Tags: Python 3, manylinux: glibc 2.17+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.9.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d1ea234cd350d483c9b742a1baee9f1d9817a2674f43d3e82b96fb135567f927
|
|
| MD5 |
b72971ad2f6d4a295d88e35c9bfcec57
|
|
| BLAKE2b-256 |
3edb67aa3f8f438b9fdebf98c1fcbbc810d131ec85efd9f8da8c05e602eaffb5
|
File details
Details for the file pynary-0.1.0-cp312-cp312-win_amd64.whl.
File metadata
- Download URL: pynary-0.1.0-cp312-cp312-win_amd64.whl
- Upload date:
- Size: 186.9 kB
- Tags: CPython 3.12, Windows x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.9.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
56c78ccaa6bddc6b7c54737c87db4f58d62072b4528636417aab0cc3d142e67c
|
|
| MD5 |
90a731016a01171726c403b89ceef039
|
|
| BLAKE2b-256 |
7849bf8e232a13cb9f7fb07e6f7b753c00b816dbd62c0a83bcbf40bf651c3d4f
|
File details
Details for the file pynary-0.1.0-cp312-cp312-manylinux2014_x86_64.manylinux_2_17_x86_64.whl.
File metadata
- Download URL: pynary-0.1.0-cp312-cp312-manylinux2014_x86_64.manylinux_2_17_x86_64.whl
- Upload date:
- Size: 1.6 MB
- Tags: CPython 3.12, manylinux: glibc 2.17+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.9.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1e3172e934e4ce7c3063940aa4f0e0dddf824edad5736492bf378e309cde4d68
|
|
| MD5 |
dcf300c859da117f986e7a2bf728830f
|
|
| BLAKE2b-256 |
f15178b4ee5e783bce4b47af3724289cc8b9a6ddd614d5be132ced2ef391c4bf
|
File details
Details for the file pynary-0.1.0-cp311-cp311-win_amd64.whl.
File metadata
- Download URL: pynary-0.1.0-cp311-cp311-win_amd64.whl
- Upload date:
- Size: 194.4 kB
- Tags: CPython 3.11, Windows x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.9.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2a296cbc7517dc905582ebb5c3c19b77351c796e83a479f3875a6b09c82b8648
|
|
| MD5 |
83d7b132ac71aefb6fac7d2737e81542
|
|
| BLAKE2b-256 |
70937b80924c02ec937b4ed64af053d72154f53af1e52cc9b437a2363408c493
|
File details
Details for the file pynary-0.1.0-cp311-cp311-manylinux2014_x86_64.manylinux_2_17_x86_64.whl.
File metadata
- Download URL: pynary-0.1.0-cp311-cp311-manylinux2014_x86_64.manylinux_2_17_x86_64.whl
- Upload date:
- Size: 1.6 MB
- Tags: CPython 3.11, manylinux: glibc 2.17+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.9.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
40ed852ddf84931559be19bcb741ff2bfe9f7f48fd1c4caaddcfac70b7d208d8
|
|
| MD5 |
de6a2c316f1d6ba603bd328ef50e89c3
|
|
| BLAKE2b-256 |
2d60745b6184274f853b8e7045d33a564dea4da5b47a6368f3e910af11393cf5
|
File details
Details for the file pynary-0.1.0-cp310-cp310-win_amd64.whl.
File metadata
- Download URL: pynary-0.1.0-cp310-cp310-win_amd64.whl
- Upload date:
- Size: 194.0 kB
- Tags: CPython 3.10, Windows x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.9.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a73493b0500eb2067b2ac2bbfb708bbfb795e272fbd40c39ec08f03076a04f09
|
|
| MD5 |
4368cee415ecb26615b39e727c8af41f
|
|
| BLAKE2b-256 |
f6ea51c7eb3ca5c48b5e2c788f1f7f3ce30d32763813f546424702e737474943
|
File details
Details for the file pynary-0.1.0-cp310-cp310-manylinux2014_x86_64.manylinux_2_17_x86_64.whl.
File metadata
- Download URL: pynary-0.1.0-cp310-cp310-manylinux2014_x86_64.manylinux_2_17_x86_64.whl
- Upload date:
- Size: 1.5 MB
- Tags: CPython 3.10, manylinux: glibc 2.17+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.9.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
19a4ca51879602e1574bea89db14b3e9e25c7ae9b93f77a404d498b1b851012a
|
|
| MD5 |
e1ea1631b290954fbc19bf40968c48de
|
|
| BLAKE2b-256 |
808181d4b686129c273bd4e28143db87335cbf55235bea8869a0b2860df5297f
|
File details
Details for the file pynary-0.1.0-cp39-cp39-win_amd64.whl.
File metadata
- Download URL: pynary-0.1.0-cp39-cp39-win_amd64.whl
- Upload date:
- Size: 209.9 kB
- Tags: CPython 3.9, Windows x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.9.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
59bc3f06b7e931d36c6868d281f71e80dc2c5473a890520feebfad5bd28cfe37
|
|
| MD5 |
2b82bb9dcca186a5179eb3e28168800b
|
|
| BLAKE2b-256 |
09a9bc75dd33b7782f95cdee3f49b6f8dcb7e166d7567c3a16f254ac1641ad65
|
File details
Details for the file pynary-0.1.0-cp39-cp39-manylinux2014_x86_64.manylinux_2_17_x86_64.whl.
File metadata
- Download URL: pynary-0.1.0-cp39-cp39-manylinux2014_x86_64.manylinux_2_17_x86_64.whl
- Upload date:
- Size: 1.4 MB
- Tags: CPython 3.9, manylinux: glibc 2.17+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.9.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b98c5b028cf6b9426e414c23fac8814a1cbaa65258448c657c7c0a27bad62b22
|
|
| MD5 |
c3d4e004f21e12deec57452c1441a967
|
|
| BLAKE2b-256 |
1a1acea6b69baa64f127f5f4d8733cd9627dfed5cb15028092f1db42a8fdcc26
|