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
 

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
 
CQCON CQ Maven Methods
CQCON CQ Maven MethodsCQCON CQ Maven Methods
CQCON CQ Maven MethodsAndrew Savory
 
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 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

Artificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxArtificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxhariprasad279825
 
SALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICESSALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICESmohitsingh558521
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.Curtis Poe
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity PlanDatabarracks
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenHervé Boutemy
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii SoldatenkoFwdays
 
What is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfWhat is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfMounikaPolabathina
 
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024BookNet Canada
 
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxThe Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxLoriGlavin3
 
What is Artificial Intelligence?????????
What is Artificial Intelligence?????????What is Artificial Intelligence?????????
What is Artificial Intelligence?????????blackmambaettijean
 
Generative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersGenerative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersRaghuram Pandurangan
 
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxUse of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxLoriGlavin3
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr BaganFwdays
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsSergiu Bodiu
 
Rise of the Machines: Known As Drones...
Rise of the Machines: Known As Drones...Rise of the Machines: Known As Drones...
Rise of the Machines: Known As Drones...Rick Flair
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Mark Simos
 
Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Manik S Magar
 
The State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxThe State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxLoriGlavin3
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024Lonnie McRorey
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Commit University
 

Recently uploaded (20)

Artificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxArtificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptx
 
SALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICESSALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICES
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity Plan
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache Maven
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko
 
What is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfWhat is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdf
 
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
 
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxThe Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
 
What is Artificial Intelligence?????????
What is Artificial Intelligence?????????What is Artificial Intelligence?????????
What is Artificial Intelligence?????????
 
Generative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersGenerative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information Developers
 
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxUse of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platforms
 
Rise of the Machines: Known As Drones...
Rise of the Machines: Known As Drones...Rise of the Machines: Known As Drones...
Rise of the Machines: Known As Drones...
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
 
Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!
 
The State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxThe State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptx
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!
 

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