Git Product home page Git Product logo

buildurl's Introduction

Discord

Badges
Build Python package semantic-release PyPI Read the Docs
Tests coverage pre-commit
Standards SemVer 2.0.0 Conventional Commits
Code Code style: black Imports: isort Checked with mypy
Repo GitHub issues GitHub stars GitHub license All Contributors

BuildURL

Simple URL builder

Read the Docs

Installation

pip

buildurl is available on pip:

pip install buildurl

GitHub

You can also install the latest version of the code directly from GitHub:

pip install git+git://github.com/MicaelJarniac/BuildURL

Usage

For more examples, see the full documentation.

from buildurl import BuildURL

# Use the `/` operator to add a string as a path to the end of the URL, like so:
url = BuildURL("https://pypi.org")
url /= "project"
url /= "buildurl"
print(url.get)  # https://pypi.org/project/buildurl

# Or, using a list:
url = BuildURL("https://pypi.org")
url /= ["project", "buildurl"]
print(url.get)  # https://pypi.org/project/buildurl

# Use the `+` operator to add a dict as a query:
url = BuildURL("https://example.com")
url += {"testing": "true"}
url += {"fruit": "apple"}
print(url.get)  # https://example.com?testing=true&fruit=apple

# Those operations can also be done without modifying the original URL:
url = BuildURL("https://python.org")
print(url.get)  # https://python.org
print((url / "doc").get)  # https://python.org/doc
print(url.get)  # https://python.org

# To get the final URL as a string:
url = BuildURL("https://example.com")
url.get
str(url)

Contributing

Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.

Please make sure to update tests as appropriate.

More details can be found in CONTRIBUTING.

Contributors โœจ


Micael Jarniac

๐Ÿ’ป ๐Ÿ“– ๐Ÿ’ก ๐Ÿค” ๐Ÿšง ๐Ÿ“ฆ ๐Ÿ“† โš ๏ธ

License

MIT

buildurl's People

Contributors

actions-user avatar allcontributors[bot] avatar micaeljarniac avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

buildurl's Issues

[FEAT] Fluent interfaces

It would be nice if methods add_path() and add_query() return self so one can easily chain calls like u.add_path('foo').add_path('bar')

Also fluent setter for trailing_slash would be helpful. E.g.:

def set_trailing_slash(self, enabled = True):
  self.trailing_slash = bool(enabled)
  return self

Option for keeping trailing slash in path

Hello, http://www.example.com/path can be different from http://www.example.com/path/ or even might not exists at all. So it would be good to have an option to keep trailing slash.

[FEAT/BUG] Automatically convert arguments of path/query to string

  • Bug part: I was trying to do something like .add_path(['user', 123]) and it didn't raise an exception during the execution of the method but only when i called .get, which is imho late.

  • Feature request: Everything should be converted to str automatically (not raising error) or at least usual types like int, float. I think it should be user's responsibility to provide desired str output and everyone knows that resulting url is always str.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.