SlideShare a Scribd company logo
1 of 20
Download to read offline
Package and distribute your
Python code
PyCon India2013,Bangalore
Sanket Saurav
Co-founder, CampusHash
Your awesome Python module is ready!
What now?
Let's go to the Cheese Shop!
No, really!
PyPI == Cheese Shop ;)
Agenda (duh!)
At the end of the talk, you can expect that your package:
*Well, not really.
**Guaranteed, or get your money back.
@sanketsaurav
Can be easily installable with pip or easy_install
Can be specified as a dependency for another package
Will have proper tests included*
Will have proper documentation*
Will make the world a better place!**
Ā·
Ā·
Ā·
Ā·
Ā·
4/20
Laying out your package
@sanketsaurav
MoonGrabber
|- bin/
|- CHANGES.txt
|- docs/
|- LICENSE.txt
|- MANIFEST.in
|- README.rst
|- setup.py
|- moongrabber/
|- __init__.py
|- moongun.py
|- battery.py
|- test/
|- __init__.py
|- test_moongun.py
|- test_fuel.py
LAYOUT
5/20
Breaking it up
@sanketsaurav
bin contains any scripts which use MoonGrabber that could be useful for the
user.
CHANGES.txt lists the changes to your module in successive versions.
Ā·
Ā·
v<version>, <date>-- Initialrelease. CHANGES.TXT
docs contains the documentation for your package should you choose to
write some. And you should always do so.
In LICENSE.txt, just paste your favorite license.
MANIFEST.in specifies the extra files that you might want to include in your
package.
Ā·
Ā·
Ā·
include*.txt
include*.json
recursive-includedocs *.txt
MANIFEST.IN
6/20
Breaking it up
@sanketsaurav
The README.txt file should be written in reStructuredText, so that PyPI can
use it to generate the package's PyPI page.
Ā·
===========
MoonGrabber
===========
MoonGrabber is asuper-awesomemodulewhichlets youstealtheMoon.
Butpromiseto putitback.Youcanuseitlikethis::
#!/usr/bin/envpython
frommoongrabber importbattery, moongun
if battery.is_full():
moon=moongun.grab_moon(planet="Earth")
README.RST
7/20
Writing your setup.py
@sanketsaurav
fromdistutils.coreimportsetup
setup(
name='MoonGrabber',
version='0.4.2',
author='Dr. Nefario',
author_email='nef@grulabs.com',
packages=['moongrabber', 'moongrabber.test'],
scripts=['bin/clean-gun.py','bin/recharge-battery.py'],
url='http://pypi.python.org/pypi/MoonGrabber/',
license='LICENSE.txt',
description='StealtheMoonfromyour favoriteplanet.',
long_description=open('README.rst').read(),
install_requires=[
"Django >=1.1.1"
],
)
SETUP.PY
8/20
Creating a source distribution
@sanketsaurav
The sdist command creates a source distribution of your package.Ā·
$pythonsetup.py sdist SHELL
It creates a MANIFEST file, a dist directory in your project folder.Ā·
This directory contains your archived distribution file. In this case, it is
MoonGrabber-0.4.2.tar.gz.
-
9/20
The Cheese Shop!
Register yourself with PyPI
@sanketsaurav
$pythonsetup.py register SHELL
If you're already registered as a user on PyPI, this will register your package.
If not, follow the instructions and the console and regsiter yourself. Then run
the command again to register the package.
Ā·
Ā·
$pythonsetup.py sdistupload SHELL
This will re-build the source distribution and upload it to PyPI.Ā·
Whenever you want to update the package, you can use this command.-
10/20
And...you're done! Yay!
But there's more...
Let's dig deeper
Add some classifiers
@sanketsaurav
Classifiers are used to additional metadata to your package.
The classifiers argument in the setup() function takes a list of classifier strings.
The list of strings can be found at
pypi.python.org/pypi?%3Aaction=list_classifiers.
Ā·
Ā·
Ā·
13/20
More with modules
@sanketsaurav
packages_dir ={ '' : 'foo', 'bar' : 'boo' } SETUP()
Use it when you source folder layout is different from your package layout.Ā·
py_modules =['foo', 'bar.zoo'] SETUP()
Use it to include individual modules.Ā·
14/20
Extension modules
@sanketsaurav
ext_package='pkg' SETUP()
Use it to list extension packages.Ā·
ext_modules=[
Extension('foo',
['foo.c']
)
]
SETUP()
Use it to add extension modules, if you may.Ā·
library_dirs=['/usr/X11R6/lib'],
libraries=['X11', 'Xt']
SETUP()
Use it to include external libraries.Ā·
15/20
Adding more data
@sanketsaurav
package_data={'mypkg': ['data/*.dat']} SETUP()
You can include data which is critical to your package.Ā·
data_files=[('bitmaps', ['bm/b1.gif', 'bm/b2.gif']),
('config', ['cfg/data.cfg']),
('/etc/init.d', ['init-script'])]
)
SETUP()
You can add external data files too.Ā·
16/20
Creating built distributions
@sanketsaurav
$pythonsetup.py bdist SHELL
This would create an archived built distribution. This is a dumb build.Ā·
$pythonsetup.py bdist_rpm
$pythonsetup.py bdist_wininst
$pythonsetup.py bdist_msi
SHELL
You can build these binaries on the respective platforms.Ā·
17/20
Do a setup.cfg
Because doing setup() is too mainstream ;)
@sanketsaurav
[bdist_rpm]
release=1
packager =Greg Ward
doc_files =CHANGES.txt
README.txt
USAGE.txt
doc/
examples/
[build_ext]
inplace=1
SETUP.CFG
Use this when you cannot have everything predefined. Users can edit this file
to customize their installation.
Ā·
18/20
I love questions! LOL JK.
PyPI == Cheese Shop ;)
Thank You!
You have been a great audience!
twitter @sanketsaurav
www blog.sanketsaurav.com
github sanketsaurav

More Related Content

Viewers also liked

Hexagonal Design in Django
Hexagonal Design in DjangoHexagonal Design in Django
Hexagonal Design in Djangomvschaik
Ā 
Postgres performance for humans
Postgres performance for humansPostgres performance for humans
Postgres performance for humansCraig Kerstiens
Ā 
Moving from Django Apps to Services
Moving from Django Apps to ServicesMoving from Django Apps to Services
Moving from Django Apps to ServicesCraig Kerstiens
Ā 
Introduction to hexagonal architecture
Introduction to hexagonal architectureIntroduction to hexagonal architecture
Introduction to hexagonal architectureManel SellƩs
Ā 
DDD session BrownBagLunch (FR)
DDD session BrownBagLunch (FR)DDD session BrownBagLunch (FR)
DDD session BrownBagLunch (FR)Cyrille Martraire
Ā 
Developing Software As A Service App with Python & Django
Developing Software As A Service App with Python & DjangoDeveloping Software As A Service App with Python & Django
Developing Software As A Service App with Python & DjangoAllan Mangune
Ā 
Code & Cannoli - Domain Driven Design
Code & Cannoli - Domain Driven DesignCode & Cannoli - Domain Driven Design
Code & Cannoli - Domain Driven DesignFrank Levering
Ā 
Domain-driven design
Domain-driven designDomain-driven design
Domain-driven designKnoldus Inc.
Ā 
Domain Driven Design
Domain Driven DesignDomain Driven Design
Domain Driven DesignRyan Riley
Ā 
Domain Driven Design and Hexagonal Architecture with Rails
Domain Driven Design and Hexagonal Architecture with RailsDomain Driven Design and Hexagonal Architecture with Rails
Domain Driven Design and Hexagonal Architecture with RailsDeclan Whelan
Ā 
Legacy Code: Evolve or Rewrite?
Legacy Code: Evolve or Rewrite?Legacy Code: Evolve or Rewrite?
Legacy Code: Evolve or Rewrite?Cyrille Martraire
Ā 
Refactoring for Domain Driven Design
Refactoring for Domain Driven DesignRefactoring for Domain Driven Design
Refactoring for Domain Driven DesignDavid Berliner
Ā 
Why Domain-Driven Design Matters
Why Domain-Driven Design MattersWhy Domain-Driven Design Matters
Why Domain-Driven Design MattersMathias Verraes
Ā 
Real Life Clean Architecture
Real Life Clean ArchitectureReal Life Clean Architecture
Real Life Clean ArchitectureMattia Battiston
Ā 
A year with event sourcing and CQRS
A year with event sourcing and CQRSA year with event sourcing and CQRS
A year with event sourcing and CQRSSteve Pember
Ā 
A Practical Guide to Domain Driven Design: Presentation Slides
A Practical Guide to Domain Driven Design: Presentation SlidesA Practical Guide to Domain Driven Design: Presentation Slides
A Practical Guide to Domain Driven Design: Presentation Slidesthinkddd
Ā 
CQRS and Event Sourcing, An Alternative Architecture for DDD
CQRS and Event Sourcing, An Alternative Architecture for DDDCQRS and Event Sourcing, An Alternative Architecture for DDD
CQRS and Event Sourcing, An Alternative Architecture for DDDDennis Doomen
Ā 
Domain Driven Design 101
Domain Driven Design 101Domain Driven Design 101
Domain Driven Design 101Richard Dingwall
Ā 

Viewers also liked (20)

Organise a Code Dojo!
Organise a Code Dojo!Organise a Code Dojo!
Organise a Code Dojo!
Ā 
Hexagonal Design in Django
Hexagonal Design in DjangoHexagonal Design in Django
Hexagonal Design in Django
Ā 
Python SOLID
Python SOLIDPython SOLID
Python SOLID
Ā 
Postgres performance for humans
Postgres performance for humansPostgres performance for humans
Postgres performance for humans
Ā 
Moving from Django Apps to Services
Moving from Django Apps to ServicesMoving from Django Apps to Services
Moving from Django Apps to Services
Ā 
Introduction to hexagonal architecture
Introduction to hexagonal architectureIntroduction to hexagonal architecture
Introduction to hexagonal architecture
Ā 
DDD session BrownBagLunch (FR)
DDD session BrownBagLunch (FR)DDD session BrownBagLunch (FR)
DDD session BrownBagLunch (FR)
Ā 
Developing Software As A Service App with Python & Django
Developing Software As A Service App with Python & DjangoDeveloping Software As A Service App with Python & Django
Developing Software As A Service App with Python & Django
Ā 
Code & Cannoli - Domain Driven Design
Code & Cannoli - Domain Driven DesignCode & Cannoli - Domain Driven Design
Code & Cannoli - Domain Driven Design
Ā 
Domain-driven design
Domain-driven designDomain-driven design
Domain-driven design
Ā 
Domain Driven Design
Domain Driven DesignDomain Driven Design
Domain Driven Design
Ā 
Domain Driven Design and Hexagonal Architecture with Rails
Domain Driven Design and Hexagonal Architecture with RailsDomain Driven Design and Hexagonal Architecture with Rails
Domain Driven Design and Hexagonal Architecture with Rails
Ā 
Legacy Code: Evolve or Rewrite?
Legacy Code: Evolve or Rewrite?Legacy Code: Evolve or Rewrite?
Legacy Code: Evolve or Rewrite?
Ā 
Refactoring for Domain Driven Design
Refactoring for Domain Driven DesignRefactoring for Domain Driven Design
Refactoring for Domain Driven Design
Ā 
Why Domain-Driven Design Matters
Why Domain-Driven Design MattersWhy Domain-Driven Design Matters
Why Domain-Driven Design Matters
Ā 
Real Life Clean Architecture
Real Life Clean ArchitectureReal Life Clean Architecture
Real Life Clean Architecture
Ā 
A year with event sourcing and CQRS
A year with event sourcing and CQRSA year with event sourcing and CQRS
A year with event sourcing and CQRS
Ā 
A Practical Guide to Domain Driven Design: Presentation Slides
A Practical Guide to Domain Driven Design: Presentation SlidesA Practical Guide to Domain Driven Design: Presentation Slides
A Practical Guide to Domain Driven Design: Presentation Slides
Ā 
CQRS and Event Sourcing, An Alternative Architecture for DDD
CQRS and Event Sourcing, An Alternative Architecture for DDDCQRS and Event Sourcing, An Alternative Architecture for DDD
CQRS and Event Sourcing, An Alternative Architecture for DDD
Ā 
Domain Driven Design 101
Domain Driven Design 101Domain Driven Design 101
Domain Driven Design 101
Ā 

Similar to Package and distribute your Python code

ė‚˜ė„ ķ•  ģˆ˜ ģžˆė‹¤ ģ˜¤ķ”ˆģ†ŒģŠ¤
ė‚˜ė„ ķ•  ģˆ˜ ģžˆė‹¤ ģ˜¤ķ”ˆģ†ŒģŠ¤ė‚˜ė„ ķ•  ģˆ˜ ģžˆė‹¤ ģ˜¤ķ”ˆģ†ŒģŠ¤
ė‚˜ė„ ķ•  ģˆ˜ ģžˆė‹¤ ģ˜¤ķ”ˆģ†ŒģŠ¤ķšØģ¤€ ź°•
Ā 
Python packaging and dependency resolution
Python packaging and dependency resolutionPython packaging and dependency resolution
Python packaging and dependency resolutionTatiana Al-Chueyr
Ā 
Christian Strappazzon - Presentazione Python Milano - Codemotion Milano 2017
Christian Strappazzon - Presentazione Python Milano - Codemotion Milano 2017Christian Strappazzon - Presentazione Python Milano - Codemotion Milano 2017
Christian Strappazzon - Presentazione Python Milano - Codemotion Milano 2017Codemotion
Ā 
Arbeiten mit distribute, pip und virtualenv
Arbeiten mit distribute, pip und virtualenvArbeiten mit distribute, pip und virtualenv
Arbeiten mit distribute, pip und virtualenvMarkus Zapke-GrĆ¼ndemann
Ā 
A Hands-On Set of Programming Problems Using Python and OpenCV
A Hands-On Set of Programming Problems Using Python and OpenCVA Hands-On Set of Programming Problems Using Python and OpenCV
A Hands-On Set of Programming Problems Using Python and OpenCVNader Karimi
Ā 
Using the pip package manager for Odoo
Using the pip package manager for OdooUsing the pip package manager for Odoo
Using the pip package manager for OdooOdoo
Ā 
Using the "pip" package manager for Odoo/OpenERP - Opendays 2014
Using the "pip" package manager for Odoo/OpenERP - Opendays 2014Using the "pip" package manager for Odoo/OpenERP - Opendays 2014
Using the "pip" package manager for Odoo/OpenERP - Opendays 2014Daniel Reis
Ā 
Overcoming CMake Configuration Issues Webinar
Overcoming CMake Configuration Issues WebinarOvercoming CMake Configuration Issues Webinar
Overcoming CMake Configuration Issues WebinarICS
Ā 
Virtual Environment and Web development using Django
Virtual Environment and Web development using DjangoVirtual Environment and Web development using Django
Virtual Environment and Web development using DjangoSunil kumar Mohanty
Ā 
Virtualenv
VirtualenvVirtualenv
VirtualenvWEBdeBS
Ā 
Arbeiten mit distribute, pip und virtualenv
Arbeiten mit distribute, pip und virtualenvArbeiten mit distribute, pip und virtualenv
Arbeiten mit distribute, pip und virtualenvMarkus Zapke-GrĆ¼ndemann
Ā 
CQ Maven Methods
CQ Maven MethodsCQ Maven Methods
CQ Maven Methodsconnectwebex
Ā 
CQCON CQ Maven Methods
CQCON CQ Maven MethodsCQCON CQ Maven Methods
CQCON CQ Maven MethodsAndrew Savory
Ā 
Getting Started With Aura
Getting Started With AuraGetting Started With Aura
Getting Started With AuraChris Tankersley
Ā 
Distributing Sage / Python Code, The Right Way
Distributing Sage / Python Code, The Right WayDistributing Sage / Python Code, The Right Way
Distributing Sage / Python Code, The Right Waymmasdeu
Ā 
Python Interview Questions And Answers 2019 | Edureka
Python Interview Questions And Answers 2019 | EdurekaPython Interview Questions And Answers 2019 | Edureka
Python Interview Questions And Answers 2019 | EdurekaEdureka!
Ā 
Adventures in infrastructure as code
Adventures in infrastructure as codeAdventures in infrastructure as code
Adventures in infrastructure as codeJulian Simpson
Ā 
Puppet modules for Fun and Profit
Puppet modules for Fun and ProfitPuppet modules for Fun and Profit
Puppet modules for Fun and ProfitAlessandro Franceschi
Ā 
Puppet Modules for Fun and Profit
Puppet Modules for Fun and ProfitPuppet Modules for Fun and Profit
Puppet Modules for Fun and ProfitPuppet
Ā 

Similar to Package and distribute your Python code (20)

ė‚˜ė„ ķ•  ģˆ˜ ģžˆė‹¤ ģ˜¤ķ”ˆģ†ŒģŠ¤
ė‚˜ė„ ķ•  ģˆ˜ ģžˆė‹¤ ģ˜¤ķ”ˆģ†ŒģŠ¤ė‚˜ė„ ķ•  ģˆ˜ ģžˆė‹¤ ģ˜¤ķ”ˆģ†ŒģŠ¤
ė‚˜ė„ ķ•  ģˆ˜ ģžˆė‹¤ ģ˜¤ķ”ˆģ†ŒģŠ¤
Ā 
Python packaging and dependency resolution
Python packaging and dependency resolutionPython packaging and dependency resolution
Python packaging and dependency resolution
Ā 
Christian Strappazzon - Presentazione Python Milano - Codemotion Milano 2017
Christian Strappazzon - Presentazione Python Milano - Codemotion Milano 2017Christian Strappazzon - Presentazione Python Milano - Codemotion Milano 2017
Christian Strappazzon - Presentazione Python Milano - Codemotion Milano 2017
Ā 
Arbeiten mit distribute, pip und virtualenv
Arbeiten mit distribute, pip und virtualenvArbeiten mit distribute, pip und virtualenv
Arbeiten mit distribute, pip und virtualenv
Ā 
A Hands-On Set of Programming Problems Using Python and OpenCV
A Hands-On Set of Programming Problems Using Python and OpenCVA Hands-On Set of Programming Problems Using Python and OpenCV
A Hands-On Set of Programming Problems Using Python and OpenCV
Ā 
Using the pip package manager for Odoo
Using the pip package manager for OdooUsing the pip package manager for Odoo
Using the pip package manager for Odoo
Ā 
Using the "pip" package manager for Odoo/OpenERP - Opendays 2014
Using the "pip" package manager for Odoo/OpenERP - Opendays 2014Using the "pip" package manager for Odoo/OpenERP - Opendays 2014
Using the "pip" package manager for Odoo/OpenERP - Opendays 2014
Ā 
Overcoming CMake Configuration Issues Webinar
Overcoming CMake Configuration Issues WebinarOvercoming CMake Configuration Issues Webinar
Overcoming CMake Configuration Issues Webinar
Ā 
Virtual Environment and Web development using Django
Virtual Environment and Web development using DjangoVirtual Environment and Web development using Django
Virtual Environment and Web development using Django
Ā 
Virtualenv
VirtualenvVirtualenv
Virtualenv
Ā 
Bake by cake php2.0
Bake by cake php2.0Bake by cake php2.0
Bake by cake php2.0
Ā 
Arbeiten mit distribute, pip und virtualenv
Arbeiten mit distribute, pip und virtualenvArbeiten mit distribute, pip und virtualenv
Arbeiten mit distribute, pip und virtualenv
Ā 
CQ Maven Methods
CQ Maven MethodsCQ Maven Methods
CQ Maven Methods
Ā 
CQCON CQ Maven Methods
CQCON CQ Maven MethodsCQCON CQ Maven Methods
CQCON CQ Maven Methods
Ā 
Getting Started With Aura
Getting Started With AuraGetting Started With Aura
Getting Started With Aura
Ā 
Distributing Sage / Python Code, The Right Way
Distributing Sage / Python Code, The Right WayDistributing Sage / Python Code, The Right Way
Distributing Sage / Python Code, The Right Way
Ā 
Python Interview Questions And Answers 2019 | Edureka
Python Interview Questions And Answers 2019 | EdurekaPython Interview Questions And Answers 2019 | Edureka
Python Interview Questions And Answers 2019 | Edureka
Ā 
Adventures in infrastructure as code
Adventures in infrastructure as codeAdventures in infrastructure as code
Adventures in infrastructure as code
Ā 
Puppet modules for Fun and Profit
Puppet modules for Fun and ProfitPuppet modules for Fun and Profit
Puppet modules for Fun and Profit
Ā 
Puppet Modules for Fun and Profit
Puppet Modules for Fun and ProfitPuppet Modules for Fun and Profit
Puppet Modules for Fun and Profit
Ā 

Recently uploaded

Exploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with MilvusExploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with MilvusZilliz
Ā 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century educationjfdjdjcjdnsjd
Ā 
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...apidays
Ā 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processorsdebabhi2
Ā 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingEdi Saputra
Ā 
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Victor Rentea
Ā 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
Ā 
FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024The Digital Insurer
Ā 
Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024The Digital Insurer
Ā 
CNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In PakistanCNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In Pakistandanishmna97
Ā 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FMESafe Software
Ā 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDropbox
Ā 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoffsammart93
Ā 
Ransomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdfRansomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdfOverkill Security
Ā 
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...apidays
Ā 
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...Zilliz
Ā 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businesspanagenda
Ā 
Corporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxCorporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxRustici Software
Ā 
ICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesrafiqahmad00786416
Ā 

Recently uploaded (20)

Exploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with MilvusExploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with Milvus
Ā 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
Ā 
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Ā 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
Ā 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
Ā 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Ā 
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Ā 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
Ā 
FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024
Ā 
Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024
Ā 
CNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In PakistanCNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In Pakistan
Ā 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Ā 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor Presentation
Ā 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Ā 
Ransomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdfRansomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdf
Ā 
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Ā 
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Ā 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
Ā 
Corporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxCorporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptx
Ā 
ICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesICT role in 21st century education and its challenges
ICT role in 21st century education and its challenges
Ā 

Package and distribute your Python code

  • 1. Package and distribute your Python code PyCon India2013,Bangalore Sanket Saurav Co-founder, CampusHash
  • 2. Your awesome Python module is ready! What now?
  • 3. Let's go to the Cheese Shop! No, really! PyPI == Cheese Shop ;)
  • 4. Agenda (duh!) At the end of the talk, you can expect that your package: *Well, not really. **Guaranteed, or get your money back. @sanketsaurav Can be easily installable with pip or easy_install Can be specified as a dependency for another package Will have proper tests included* Will have proper documentation* Will make the world a better place!** Ā· Ā· Ā· Ā· Ā· 4/20
  • 5. Laying out your package @sanketsaurav MoonGrabber |- bin/ |- CHANGES.txt |- docs/ |- LICENSE.txt |- MANIFEST.in |- README.rst |- setup.py |- moongrabber/ |- __init__.py |- moongun.py |- battery.py |- test/ |- __init__.py |- test_moongun.py |- test_fuel.py LAYOUT 5/20
  • 6. Breaking it up @sanketsaurav bin contains any scripts which use MoonGrabber that could be useful for the user. CHANGES.txt lists the changes to your module in successive versions. Ā· Ā· v<version>, <date>-- Initialrelease. CHANGES.TXT docs contains the documentation for your package should you choose to write some. And you should always do so. In LICENSE.txt, just paste your favorite license. MANIFEST.in specifies the extra files that you might want to include in your package. Ā· Ā· Ā· include*.txt include*.json recursive-includedocs *.txt MANIFEST.IN 6/20
  • 7. Breaking it up @sanketsaurav The README.txt file should be written in reStructuredText, so that PyPI can use it to generate the package's PyPI page. Ā· =========== MoonGrabber =========== MoonGrabber is asuper-awesomemodulewhichlets youstealtheMoon. Butpromiseto putitback.Youcanuseitlikethis:: #!/usr/bin/envpython frommoongrabber importbattery, moongun if battery.is_full(): moon=moongun.grab_moon(planet="Earth") README.RST 7/20
  • 8. Writing your setup.py @sanketsaurav fromdistutils.coreimportsetup setup( name='MoonGrabber', version='0.4.2', author='Dr. Nefario', author_email='nef@grulabs.com', packages=['moongrabber', 'moongrabber.test'], scripts=['bin/clean-gun.py','bin/recharge-battery.py'], url='http://pypi.python.org/pypi/MoonGrabber/', license='LICENSE.txt', description='StealtheMoonfromyour favoriteplanet.', long_description=open('README.rst').read(), install_requires=[ "Django >=1.1.1" ], ) SETUP.PY 8/20
  • 9. Creating a source distribution @sanketsaurav The sdist command creates a source distribution of your package.Ā· $pythonsetup.py sdist SHELL It creates a MANIFEST file, a dist directory in your project folder.Ā· This directory contains your archived distribution file. In this case, it is MoonGrabber-0.4.2.tar.gz. - 9/20
  • 10. The Cheese Shop! Register yourself with PyPI @sanketsaurav $pythonsetup.py register SHELL If you're already registered as a user on PyPI, this will register your package. If not, follow the instructions and the console and regsiter yourself. Then run the command again to register the package. Ā· Ā· $pythonsetup.py sdistupload SHELL This will re-build the source distribution and upload it to PyPI.Ā· Whenever you want to update the package, you can use this command.- 10/20
  • 13. Add some classifiers @sanketsaurav Classifiers are used to additional metadata to your package. The classifiers argument in the setup() function takes a list of classifier strings. The list of strings can be found at pypi.python.org/pypi?%3Aaction=list_classifiers. Ā· Ā· Ā· 13/20
  • 14. More with modules @sanketsaurav packages_dir ={ '' : 'foo', 'bar' : 'boo' } SETUP() Use it when you source folder layout is different from your package layout.Ā· py_modules =['foo', 'bar.zoo'] SETUP() Use it to include individual modules.Ā· 14/20
  • 15. Extension modules @sanketsaurav ext_package='pkg' SETUP() Use it to list extension packages.Ā· ext_modules=[ Extension('foo', ['foo.c'] ) ] SETUP() Use it to add extension modules, if you may.Ā· library_dirs=['/usr/X11R6/lib'], libraries=['X11', 'Xt'] SETUP() Use it to include external libraries.Ā· 15/20
  • 16. Adding more data @sanketsaurav package_data={'mypkg': ['data/*.dat']} SETUP() You can include data which is critical to your package.Ā· data_files=[('bitmaps', ['bm/b1.gif', 'bm/b2.gif']), ('config', ['cfg/data.cfg']), ('/etc/init.d', ['init-script'])] ) SETUP() You can add external data files too.Ā· 16/20
  • 17. Creating built distributions @sanketsaurav $pythonsetup.py bdist SHELL This would create an archived built distribution. This is a dumb build.Ā· $pythonsetup.py bdist_rpm $pythonsetup.py bdist_wininst $pythonsetup.py bdist_msi SHELL You can build these binaries on the respective platforms.Ā· 17/20
  • 18. Do a setup.cfg Because doing setup() is too mainstream ;) @sanketsaurav [bdist_rpm] release=1 packager =Greg Ward doc_files =CHANGES.txt README.txt USAGE.txt doc/ examples/ [build_ext] inplace=1 SETUP.CFG Use this when you cannot have everything predefined. Users can edit this file to customize their installation. Ā· 18/20
  • 19. I love questions! LOL JK. PyPI == Cheese Shop ;)
  • 20. Thank You! You have been a great audience! twitter @sanketsaurav www blog.sanketsaurav.com github sanketsaurav