https://github.com/palantir/conjure-python
Conjure generator for Python clients
https://github.com/palantir/conjure-python
octo-correct-managed
Last synced: about 2 months ago
JSON representation
Conjure generator for Python clients
- Host: GitHub
- URL: https://github.com/palantir/conjure-python
- Owner: palantir
- License: apache-2.0
- Created: 2018-06-21T15:51:20.000Z (almost 7 years ago)
- Default Branch: develop
- Last Pushed: 2025-04-02T16:45:51.000Z (2 months ago)
- Last Synced: 2025-04-02T17:36:15.152Z (2 months ago)
- Topics: octo-correct-managed
- Language: Java
- Homepage:
- Size: 1.96 MB
- Stars: 21
- Watchers: 268
- Forks: 19
- Open Issues: 13
-
Metadata Files:
- Readme: README.md
- Changelog: changelog/3.11.6/fix-windows-batch-scripts.v2.yml
- Contributing: CONTRIBUTING.md
- License: LICENSE
Awesome Lists containing this project
README
# Conjure-Python  [](https://opensource.org/licenses/Apache-2.0)
_CLI to generate Python classes from [Conjure API definitions](https://github.com/palantir/conjure)._
## Overview
The generated clients provide a simple interface for executing statically typed remote procedure calls from Python 2 or 3.
## Usage
The recommended way to use conjure-python is via a build tool like [gradle-conjure](https://github.com/palantir/gradle-conjure). However, if you don't want to use gradle-conjure, there is also an executable which conforms to [RFC 002](https://github.com/palantir/conjure/blob/master/docs/rfc/002-contract-for-conjure-generators.md).
Usage: conjure-python generate [...options]
--packageName package name that will appear in setup.py
--packageVersion version number that will appear in setup.py
--packageDescription description that will appear in setup.py
--packageUrl url that will appear in setup.py
--packageAuthor author that will appear in setup.py
--writeCondaRecipe use this boolean option to generate a `conda_recipe/meta.yaml`## Example generated objects
- **Conjure object: [ManyFieldExample](https://github.com/palantir/conjure-python/blob/develop/conjure-python-core/src/test/resources/types/expected/package_name/_impl.py#L1022)**
```python
example = ManyFieldExample('alias', 1.0, 1, [], {}, [])
```- **Conjure union: [UnionTypeExample](https://github.com/palantir/conjure-python/blob/develop/conjure-python-core/src/test/resources/types/expected/package_name/_impl.py#L1465)**
```python
stringVariant = UnionTypeExample(string_example="foo")
```- **Conjure enum: [EnumExample](https://github.com/palantir/conjure-python/blob/develop/conjure-python-core/src/test/resources/types/expected/package_name/_impl.py#L888)**
```python
one = EnumExample.ONE;
print(one); // prints: 'ONE'
```- **Conjure alias: [StringAliasExample](https://github.com/palantir/conjure-python/blob/develop/conjure-python-core/src/test/resources/types/expected/package_name/_impl.py#L1895)**
Python uses structural (duck-typing) so aliases are currently transparent.
## Example Client interfaces
Example service interface: [TestService](https://github.com/palantir/conjure-python/blob/develop/conjure-python-core/src/test/resources/services/expected/package_name/_impl.py#L21)```python
class TestService(Service):
"""A Markdown description of the service. "Might end with quotes"
"""def get_file_systems(self, auth_header):
# type: (str) -> Dict[str, BackingFileSystem]
"""Returns a mapping from file system id to backing file system configuration.
"""_headers = {
'Accept': 'application/json',
'Authorization': auth_header,
} # type: Dict[str, Any]_params = {
} # type: Dict[str, Any]_path_params = {
} # type: Dict[str, Any]_json = None # type: Any
_path = '/catalog/fileSystems'
_path = _path.format(**_path_params)_response = self._request( # type: ignore
'GET',
self._uri + _path,
params=_params,
headers=_headers,
json=_json)_decoder = ConjureDecoder()
return _decoder.decode(_response.json(), DictType(str, BackingFileSystem))
```## Constructing clients
Use [conjure-python-client](https://github.com/palantir/conjure-python-client) which leverages [requests](http://docs.python-requests.org/en/master/):
```python
from conjure_python_client import RequestsClient, ServiceConfigurationconfig = ServiceConfiguration()
config.uris = ["https://foo.com/api"]
service = RequestsClient.create(TestService,
user_agent="something/1.2.3",
service_config=config)service.do_something(auth_header, param)
```## mypy typings
Generated code has [mypy](http://mypy-lang.org/) comments for optional static typing.
```diff
class TestService(Service):
'''A Markdown description of the service.'''def get_file_systems(self, authHeader):
+ # type: (str) -> Dict[str, BackingFileSystem]
```## Contributing
See the [CONTRIBUTING.md](./CONTRIBUTING.md) document.
## License
This project is made available under the [Apache 2.0 License](/LICENSE).