A sample Python library to generate motivation quotes.
Project description
My Library
A sample Python library.
Installation
To install this library, run the following command:
pip install my_library
# Create Python Module Guide
November 12, 2024
This conversation may reflect the link creator’s personalized data, which isn’t shared and can meaningfully change how the model responds.
## Step 1: Create Your Python Module/Library
Project Structure: Start by organizing your project into a folder structure like this:
```markdown
my_library/
├── my_library/
│ ├── __init__.py
│ ├── core.py
│ └── utils.py
├── tests/
│ └── test_core.py
├── README.md
├── LICENSE
├── setup.py
├── pyproject.toml
└── requirements.txt
my_library/: Contains your main package code. tests/: Holds your test files. README.md: Contains documentation for your project. LICENSE: Specifies the license type (e.g., MIT License). setup.py: Provides metadata and instructions to package your module. pyproject.toml: Defines build system requirements (e.g., setuptools). requirements.txt: Lists dependencies your package needs.
Step 2: Write Your Python Code
Create a Python module (e.g., core.py) with functions or classes you want to package.
# my_library/core.py
def greet(name):
return f"Hello, {name}!"
Step 3: Add an init.py File
This file makes your directory a package. You can import your functions here if needed.
# my_library/__init__.py
from .core import greet
Step 4: Write Tests
Testing ensures that your code works as expected.
# tests/test_core.py
from my_library.core import greet
def test_greet():
assert greet("Sridhar") == "Hello, Sridhar!"
Run your tests using a tool like pytest:
pip install pytest
pytest
Step 5: Create setup.py
This file is used to define your package metadata.
from setuptools import setup, find_packages
setup(
name="my_library",
version="0.1.0",
description="A sample Python library",
author="Sridhar",
author_email="your_email@example.com",
url="https://github.com/your_username/my_library",
packages=find_packages(),
install_requires=[],
classifiers=[
"Programming Language :: Python :: 3",
"License :: OSI Approved :: MIT License",
"Operating System :: OS Independent",
],
python_requires='>=3.6',
)
Step 6: Create pyproject.toml
This file tells Python which build system to use.
[build-system]
requires = ["setuptools", "wheel"]
build-backend = "setuptools.build_meta"
Step 7: Create README.md and LICENSE
README.md: Add documentation, usage examples, etc. LICENSE: Include a license file, like the MIT License.
Step 7: Create README.md and LICENSE
README.md
# My Library
A sample Python library.
## Installation
To install this library, run the following command:
```bash
pip install my_library
Usage
Here's an example of how to use this library:
from my_library import greet
print(greet("Sridhar"))
Contributing
Contributions are welcome! If you'd like to contribute to this library, please fork the repository and submit a pull request.
License
This library is licensed under the MIT License. See the LICENSE file for more information.
#### LICENSE
```text
MIT License
Copyright (c) 2024 Sridhar
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
Step 8: Generate Distribution Files
Now, it's time to package your project.
pip install setuptools wheel
python setup.py sdist bdist_wheel
This will create a dist/ directory with .tar.gz and .whl files.
Step 9: Upload to PyPI
Create a PyPI account: If you don’t have one, create an account on PyPI.
Install twine: This tool helps upload your package to PyPI.
pip install twine
Upload Your Package:
twine upload dist/*
Enter your credentials: You’ll be prompted for your PyPI username and password.
Step 10: Test Your Package
After uploading, you can install your package using:
pip install my_library
And test it:
from my_library import greet
print(greet("Sridhar"))
Step 11: Update Your Package
When making updates, increase the version number in setup.py and pyproject.toml. Rebuild and upload the new version:
python setup.py sdist bdist_wheel
twine upload dist/*
Tips Use a virtual environment to avoid conflicts with your system packages:
python -m venv venv
source venv/bin/activate # On Windows: venv\Scripts\activate
Consider using setuptools-scm for automatic versioning if your project is hosted on GitHub.
By following these steps, you can successfully create, test, and publish your own Python module to PyPI. Happy coding, Sridhar!
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file quotesengine-0.1.0.tar.gz.
File metadata
- Download URL: quotesengine-0.1.0.tar.gz
- Upload date:
- Size: 10.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.12.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f819afe13cfd61417b47e57296a5a4f34cfd064d1b2ecc0ea906a7d823719f58
|
|
| MD5 |
0b28c304bc18bc659558533f800884b5
|
|
| BLAKE2b-256 |
f85e90cabc1c62fe9f01ee99585da2c981a5fd3556d2357943462d23c259d2b9
|
File details
Details for the file QuotesEngine-0.1.0-py3-none-any.whl.
File metadata
- Download URL: QuotesEngine-0.1.0-py3-none-any.whl
- Upload date:
- Size: 8.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.12.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ce4bfe61d0b0d92d3af53c40009f1bec54b687022703ce241f62c6ee8c1070de
|
|
| MD5 |
a56a29d99ff516253e52fb33504a9d56
|
|
| BLAKE2b-256 |
7d9584c77b34dc5d0e953f253c96b57c2ab5b8ca2f39f76b0395802cd07adfdb
|