{"id":13608961,"url":"https://github.com/simonw/python-lib","last_synced_at":"2025-03-17T14:14:31.639Z","repository":{"id":43754526,"uuid":"293300757","full_name":"simonw/python-lib","owner":"simonw","description":"Opinionated cookiecutter template for creating a new Python library","archived":false,"fork":false,"pushed_at":"2024-08-20T17:50:22.000Z","size":45,"stargazers_count":175,"open_issues_count":1,"forks_count":13,"subscribers_count":5,"default_branch":"main","last_synced_at":"2024-10-18T07:53:46.043Z","etag":null,"topics":["cookiecutter-template","pypi"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/simonw.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2020-09-06T15:04:44.000Z","updated_at":"2024-10-15T07:34:26.000Z","dependencies_parsed_at":"2024-01-16T07:22:59.671Z","dependency_job_id":"df0b194d-8a4f-4ab8-b929-1a3c7a28ab12","html_url":"https://github.com/simonw/python-lib","commit_stats":{"total_commits":36,"total_committers":2,"mean_commits":18.0,"dds":0.02777777777777779,"last_synced_commit":"e5f252c0696274ce33befaea1a1d98842d2c0fdd"},"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/simonw%2Fpython-lib","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/simonw%2Fpython-lib/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/simonw%2Fpython-lib/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/simonw%2Fpython-lib/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/simonw","download_url":"https://codeload.github.com/simonw/python-lib/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244047646,"owners_count":20389206,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["cookiecutter-template","pypi"],"created_at":"2024-08-01T19:01:31.331Z","updated_at":"2025-03-17T14:14:31.615Z","avatar_url":"https://github.com/simonw.png","language":"Python","funding_links":[],"categories":["Python","PyPi"],"sub_categories":["Table of Content"],"readme":"# python-lib cookiecutter template\n\nOpinionated cookiecutter template for creating a new Python library\n\nUse this template on your own machine with cookiecutter, or create a brand new repository based on this template entirely through the GitHub web interface using [python-lib-template-repository](https://github.com/simonw/python-lib-template-repository).\n\n## Installation\n\nYou'll need to have [cookiecutter](https://cookiecutter.readthedocs.io/) installed. I recommend pipx for this:\n```bash\npipx install cookiecutter\n```\nRegular `pip` will work OK too.\n\n## Usage\n\nRun `cookiecutter gh:simonw/python-lib` and then answer the prompts. Here's an example run:\n```bash\ncookiecutter gh:simonw/python-lib\n```\n```\nlib_name []: python lib template demo\ndescription []: Demonstrating https://github.com/simonw/python-lib\nhyphenated [python-lib-template-demo]: \nunderscored [python_lib_template_demo]: \ngithub_username []: simonw\nauthor_name []: Simon Willison\n```\nI strongly recommend accepting the suggested value for \"hyphenated\" and \"underscored\" by hitting enter on those prompts.\n\nThis will create a directory called `python-lib-template-demo` - the name you enter is converted to lowercase and uses hyphens instead of spaces.\n\nSee https://github.com/simonw/python-lib-template-demo for the output of this example.\n\n## Developing your library\n\nHaving created the new structure from the template, here's how to start working on the library.\n\nIf your library is called `my-new-library`, you can start working on it like so:\n```bash\ncd my-new-library\n# Create and activate a virtual environment:\npython -m venv venv\nsource venv/bin/activate\n# Install dependencies so you can edit the project:\npython -m pip install -e '.[test]'\n# With zsh you have to run this again for some reason:\nsource venv/bin/activate\n```\nYou can run the default test for your library like so:\n```bash\npython -m pytest\n```\nThis will execute the test in `tests/test_my_new_library.py`.\n\n## Creating a Git repository for your library\n\nYou can initialize a Git repository for your library like this:\n```bash\ncd my-new-library\ngit init\ngit add .\ngit commit -m \"Initial structure from template\"\n# Rename the 'master' branch to 'main':\ngit branch -m master main\n```\n## Publishing your library to GitHub\n\nUse https://github.com/new to create a new GitHub repository sharing the same name as your library, which should be something like `my-new-library`.\n\nPush your `main` branch to GitHub like this:\n```bash\ngit remote add origin git@github.com:YOURNAME/my-new-library.git\ngit push -u origin main\n```\nThe template will have created a GitHub Action which runs your library's test suite against every commit.\n\n## Publishing your library as a package to PyPI\n\nThe template also includes a `publish.yml` GitHub Actions workflow for publishing packages to [PyPI](https://pypi.org/), using [pypa/gh-action-pypi-publish](https://github.com/pypa/gh-action-pypi-publish).\n\nTo use this action, you need to create a PyPI account and [configure a Trusted Publisher](https://til.simonwillison.net/pypi/pypi-releases-from-github) for this package.\n\nOnce you have created your account, navigate to https://pypi.org/manage/account/publishing/ and create a \"pending publisher\" for the package. Use the following values:\n\n- **PyPI Project Name:** The name of your package\n- **Owner:** Your GitHub username or organization - the \"foo\" in `github.com/foo/bar`\n- **Repsitory name:** The name of your repository - the \"bar\" in `github.com/foo/bar`\n- **Workflow name:** `publish.yml`\n- **Environment name:** `release`\n\nNow, any time you create a new \"Release\" on GitHub the Action will build your package and push it to PyPI.\n\nThe tag for your release needs to match the `VERSION` string at the top of your `pyproject.toml` file. You should bump this version any time you release a new version of your package.\n\n## Notes on updating this cookiecutter template\n\nUpdating this cookiecutter template while keeping the [python-lib-template-repository](https://github.com/simonw/python-lib-template-repository) template repository working is a little bit complicated. Detailed notes in [issue #6](https://github.com/simonw/python-lib/issues/6), but the short version is:\n\n1. Any changes to the `{{cookiecutter.hyphenated}}/.github/workflows/*.yml` files need to be manually pushed to the [python-lib-template-demo](https://github.com/simonw/python-lib-template-demo) repository, because GitHub Actions cannot update their own workflows.\n2. Generated final versions of those workflows then need to be copied to [python-lib-template-repository .github/workflows](https://github.com/simonw/python-lib-template-repository/tree/main/.github/workflows) for the same reason.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsimonw%2Fpython-lib","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsimonw%2Fpython-lib","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsimonw%2Fpython-lib/lists"}