SlideShare a Scribd company logo
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

Organise a Code Dojo!
Organise a Code Dojo!Organise a Code Dojo!
Organise a Code Dojo!
Nicholas Tollervey
 
Hexagonal Design in Django
Hexagonal Design in DjangoHexagonal Design in Django
Hexagonal Design in Django
mvschaik
 
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 Services
Craig Kerstiens
 
Introduction to hexagonal architecture
Introduction to hexagonal architectureIntroduction to hexagonal architecture
Introduction to hexagonal architecture
Manel 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 Design
Frank Levering
 
Domain-driven design
Domain-driven designDomain-driven design
Domain-driven design
Knoldus Inc.
 
Domain Driven Design
Domain Driven DesignDomain Driven Design
Domain Driven Design
Ryan 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 Rails
Declan 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 Design
David Berliner
 
Why Domain-Driven Design Matters
Why Domain-Driven Design MattersWhy Domain-Driven Design Matters
Why Domain-Driven Design Matters
Mathias Verraes
 
Real Life Clean Architecture
Real Life Clean ArchitectureReal Life Clean Architecture
Real Life Clean Architecture
Mattia 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 CQRS
Steve 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 Slides
thinkddd
 
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
Dennis Doomen
 
Domain Driven Design 101
Domain Driven Design 101Domain Driven Design 101
Domain Driven Design 101
Richard 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 resolution
Tatiana 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 2017
Codemotion
 
Arbeiten mit distribute, pip und virtualenv
Arbeiten mit distribute, pip und virtualenvArbeiten mit distribute, pip und virtualenv
Arbeiten mit distribute, pip und virtualenv
Markus 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 OpenCV
Nader Karimi
 
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
Daniel Reis
 
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
 
Overcoming CMake Configuration Issues Webinar
Overcoming CMake Configuration Issues WebinarOvercoming CMake Configuration Issues Webinar
Overcoming CMake Configuration Issues Webinar
ICS
 
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
Sunil kumar Mohanty
 
Virtualenv
VirtualenvVirtualenv
Virtualenv
WEBdeBS
 
Arbeiten mit distribute, pip und virtualenv
Arbeiten mit distribute, pip und virtualenvArbeiten mit distribute, pip und virtualenv
Arbeiten mit distribute, pip und virtualenv
Markus Zapke-Gründemann
 
CQ Maven Methods
CQ Maven MethodsCQ Maven Methods
CQ Maven Methods
connectwebex
 
CQCON CQ Maven Methods
CQCON CQ Maven MethodsCQCON CQ Maven Methods
CQCON CQ Maven Methods
Andrew Savory
 
Getting Started With Aura
Getting Started With AuraGetting Started With Aura
Getting Started With Aura
Chris 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 Way
mmasdeu
 
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
Edureka!
 
Adventures in infrastructure as code
Adventures in infrastructure as codeAdventures in infrastructure as code
Adventures in infrastructure as code
Julian Simpson
 
Puppet modules for Fun and Profit
Puppet modules for Fun and ProfitPuppet modules for Fun and Profit
Puppet modules for Fun and Profit
Alessandro Franceschi
 
Puppet Modules for Fun and Profit
Puppet Modules for Fun and ProfitPuppet Modules for Fun and Profit
Puppet Modules for Fun and Profit
Puppet
 

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/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
 
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
 
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

Microsoft - Power Platform_G.Aspiotis.pdf
Microsoft - Power Platform_G.Aspiotis.pdfMicrosoft - Power Platform_G.Aspiotis.pdf
Microsoft - Power Platform_G.Aspiotis.pdf
Uni Systems S.M.S.A.
 
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 previewState of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
Prayukth K V
 
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdfFIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance
 
Uni Systems Copilot event_05062024_C.Vlachos.pdf
Uni Systems Copilot event_05062024_C.Vlachos.pdfUni Systems Copilot event_05062024_C.Vlachos.pdf
Uni Systems Copilot event_05062024_C.Vlachos.pdf
Uni Systems S.M.S.A.
 
Essentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FMEEssentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FME
Safe Software
 
Monitoring Java Application Security with JDK Tools and JFR Events
Monitoring Java Application Security with JDK Tools and JFR EventsMonitoring Java Application Security with JDK Tools and JFR Events
Monitoring Java Application Security with JDK Tools and JFR Events
Ana-Maria Mihalceanu
 
Elizabeth Buie - Older adults: Are we really designing for our future selves?
Elizabeth Buie - Older adults: Are we really designing for our future selves?Elizabeth Buie - Older adults: Are we really designing for our future selves?
Elizabeth Buie - Older adults: Are we really designing for our future selves?
Nexer Digital
 
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
DanBrown980551
 
By Design, not by Accident - Agile Venture Bolzano 2024
By Design, not by Accident - Agile Venture Bolzano 2024By Design, not by Accident - Agile Venture Bolzano 2024
By Design, not by Accident - Agile Venture Bolzano 2024
Pierluigi Pugliese
 
The Future of Platform Engineering
The Future of Platform EngineeringThe Future of Platform Engineering
The Future of Platform Engineering
Jemma Hussein Allen
 
DevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA ConnectDevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA Connect
Kari Kakkonen
 
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdfFIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance
 
Removing Uninteresting Bytes in Software Fuzzing
Removing Uninteresting Bytes in Software FuzzingRemoving Uninteresting Bytes in Software Fuzzing
Removing Uninteresting Bytes in Software Fuzzing
Aftab Hussain
 
Pushing the limits of ePRTC: 100ns holdover for 100 days
Pushing the limits of ePRTC: 100ns holdover for 100 daysPushing the limits of ePRTC: 100ns holdover for 100 days
Pushing the limits of ePRTC: 100ns holdover for 100 days
Adtran
 
Climate Impact of Software Testing at Nordic Testing Days
Climate Impact of Software Testing at Nordic Testing DaysClimate Impact of Software Testing at Nordic Testing Days
Climate Impact of Software Testing at Nordic Testing Days
Kari Kakkonen
 
GridMate - End to end testing is a critical piece to ensure quality and avoid...
GridMate - End to end testing is a critical piece to ensure quality and avoid...GridMate - End to end testing is a critical piece to ensure quality and avoid...
GridMate - End to end testing is a critical piece to ensure quality and avoid...
ThomasParaiso2
 
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdfFIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance
 
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
BookNet Canada
 
Epistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI supportEpistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI support
Alan Dix
 
FIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance Osaka Seminar: Overview.pdfFIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance
 

Recently uploaded (20)

Microsoft - Power Platform_G.Aspiotis.pdf
Microsoft - Power Platform_G.Aspiotis.pdfMicrosoft - Power Platform_G.Aspiotis.pdf
Microsoft - Power Platform_G.Aspiotis.pdf
 
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 previewState of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
 
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdfFIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
 
Uni Systems Copilot event_05062024_C.Vlachos.pdf
Uni Systems Copilot event_05062024_C.Vlachos.pdfUni Systems Copilot event_05062024_C.Vlachos.pdf
Uni Systems Copilot event_05062024_C.Vlachos.pdf
 
Essentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FMEEssentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FME
 
Monitoring Java Application Security with JDK Tools and JFR Events
Monitoring Java Application Security with JDK Tools and JFR EventsMonitoring Java Application Security with JDK Tools and JFR Events
Monitoring Java Application Security with JDK Tools and JFR Events
 
Elizabeth Buie - Older adults: Are we really designing for our future selves?
Elizabeth Buie - Older adults: Are we really designing for our future selves?Elizabeth Buie - Older adults: Are we really designing for our future selves?
Elizabeth Buie - Older adults: Are we really designing for our future selves?
 
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
 
By Design, not by Accident - Agile Venture Bolzano 2024
By Design, not by Accident - Agile Venture Bolzano 2024By Design, not by Accident - Agile Venture Bolzano 2024
By Design, not by Accident - Agile Venture Bolzano 2024
 
The Future of Platform Engineering
The Future of Platform EngineeringThe Future of Platform Engineering
The Future of Platform Engineering
 
DevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA ConnectDevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA Connect
 
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdfFIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
 
Removing Uninteresting Bytes in Software Fuzzing
Removing Uninteresting Bytes in Software FuzzingRemoving Uninteresting Bytes in Software Fuzzing
Removing Uninteresting Bytes in Software Fuzzing
 
Pushing the limits of ePRTC: 100ns holdover for 100 days
Pushing the limits of ePRTC: 100ns holdover for 100 daysPushing the limits of ePRTC: 100ns holdover for 100 days
Pushing the limits of ePRTC: 100ns holdover for 100 days
 
Climate Impact of Software Testing at Nordic Testing Days
Climate Impact of Software Testing at Nordic Testing DaysClimate Impact of Software Testing at Nordic Testing Days
Climate Impact of Software Testing at Nordic Testing Days
 
GridMate - End to end testing is a critical piece to ensure quality and avoid...
GridMate - End to end testing is a critical piece to ensure quality and avoid...GridMate - End to end testing is a critical piece to ensure quality and avoid...
GridMate - End to end testing is a critical piece to ensure quality and avoid...
 
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdfFIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
 
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
 
Epistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI supportEpistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI support
 
FIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance Osaka Seminar: Overview.pdfFIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance Osaka Seminar: Overview.pdf
 

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